Skip to content
Last updated

Creating a user consent application using the Python SDK

Project structure

First, we'll set up the project directory:

  1. Navigate to the directory in which you'd like to store your project.

  2. Create a folder called sinch-user-consent and navigate into it.

  3. Create a file called app.py.

Setting up your environment

Now, we'll install the prerequisites for your application.

Creating a Python virtual environment

Open a terminal or command prompt and navigate into the project folder you created. Here, you will create a virtual environment called venv. You don't need to do this, but it is recommended. Python virtual environments function as sandboxes, allowing you to install application specific packages without installing them globally.

In Windows and Mac you can create a virtual environment with the command

python -m venv venv

In Linux you can create a virtual environment with the command

virtualenv --python python venv

Now you need to activate the virtual environment.

In Windows, run the command:

venv\Scripts\activate

In Linux, the command is:

source venv/bin/activate

Now that your virtual environment is activated, you can install the dependencies your application needs to function.

This is a Flask application so you need to install Flask. You can do this with pip.

pip install flask

To effectively leverage Sinch SMS capability with Python, you need to install the SDK. You can do this with pip.

pip install sinch

If you successfully completed the Receive an SMS Message guide, you'll have used ngrok to set up a tunnel to your local server. Install ngrok with the command:

npm install ngrok -g

If you haven't already, set up a free account with ngrok. Now we've installed everything we need, we can start creating the application.

Collecting information to initialize the client

On the next page, you'll need to intialize the SDK.

Before initializing a client using this SDK, you'll need three pieces of information:

  • Your Project ID
  • An access key ID
  • An access key Secret

These values can be found on the <b>Access Keys</b> page of the Sinch Build Dashboard. You can also create new access key IDs and Secrets, if required.

Note

If you have trouble accessing the above link, ensure that you have gained access to the Conversation API by accepting the corresponding terms and conditions.