Creating an appointment reminder app with Python SDK
Creating the project structure
We're going to create the project folder and add a simple directory structure.
- Navigate to the directory in which you'd like to store your project.
- Create a folder called
sinch-appointment-reminder
and navigate into it. - Create the following directory structure:
sinch-appointment-reminder
│ .env
│ appointment_server.py
│
├───static
│ style.css
│
└───templates
patient_details.html
success.html
As you complete the tutorial, you'll learn what each of the files and folders does.
Environment Setup
We'll now install the prerequisites for the 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 calledvenv
. 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.
Installing Flask
This is a Flask application so you need to install Flask. You can do this with pip.
pip install flask
Installing Python-dotenv
We'll be loading environment variables, so you need to install Python-dotenv. You can do this with pip.
pip install python-dotenv
Installing the SDK
To effectively leverage Sinch SMS capability with Python, you need to install the SDK. You can do this with pip.
pip install sinch
Client information
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
Note:
You'll add these values to the file described in the next section (along with others).
Adding the environment variables
Your app stores information, such as your Sinch credentials, as environment variables in the.env
file. This is much more flexible and secure than simply hardcoding them.- Open the
.env
file. - Paste the following text into the
.env
file:KEY_ID='YOUR_key_id' KEY_SECRET='YOUR_key_secret' PROJECT_ID='YOUR_project_id' DEBUG=True COUNTRY_CODE_EU='YOUR_EU_country_code' COUNTRY_CODE_US='+1' FROM_NUMBER='YOUR_sinch_number' SMS_REGION='YOUR_sms_region(us/eu)'
- Populate the fields in the file with your own values. Refer to the table below for guidance:
Field Description KEY_ID
Your access key ID, used for authentication. Refer to the Client information section for more information. KEY_SECRET
Your access key secret, used for authentication. Refer to the Client information section for more information. PROJECT_ID
Your project ID. Refer to the Client information section for more information. DEBUG
Set to True
to enable debugging.COUNTRY_CODE_EU
If you live in the EU or UK, this is the country code of your home country. For example the UK country code is +44
.COUNTRY_CODE_US
If you live in the US, this is the country code of your home country. For the US, it's +1
.FROM_NUMBER
Any number you've assigned to your Sinch account. Find the number on your Customer Dashboard by clicking the service plan ID link and scrolling to the bottom of the page. SMS_REGION
The region in which you would like to send SMS messages. Either us
oreu
.