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.

  1. Navigate to the directory in which you'd like to store your project.
  2. Create a folder called sinch-appointment-reminder and navigate into it.
  3. Create the following directory structure:
Copy
Copied
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 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

Copy
Copied
python -m venv venv

In Linux you can create a virtual environment with the command

Copy
Copied
virtualenv --python python venv

Now you need to activate the virtual environment.

In Windows, run the command:

Copy
Copied
venv\Scripts\activate

In Linux, the command is:

Copy
Copied
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.

Copy
Copied
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.

Copy
Copied
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.

Copy
Copied
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
These values can be found on the Access Keys page of the Customer 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.

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.

  1. Open the .env file.
  2. Paste the following text into the .env file:
    Copy
    Copied
    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)'
  3. Populate the fields in the file with your own values. Refer to the table below for guidance:
    FieldDescription
    KEY_IDYour access key ID, used for authentication. Refer to the Client information section for more information.
    KEY_SECRETYour access key secret, used for authentication. Refer to the Client information section for more information.
    PROJECT_IDYour project ID. Refer to the Client information section for more information.
    DEBUGSet to True to enable debugging.
    COUNTRY_CODE_EUIf 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_USIf you live in the US, this is the country code of your home country. For the US, it's +1.
    FROM_NUMBERAny 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_REGIONThe region in which you would like to send SMS messages. Either us or eu.


We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.