Backend Services Dev Environment Setup

Setup the Walrus and Default Services for Development

We are going to assume that your working directory is named ./working-dir. Please rename this path whenever you find it your working dir.

1. Clone the Repository

cd ./working-dir
git clone

2. Create a Virtual Environment

Create the virtual environment and activate it.

python3 -m venv venv3 
source venv3/bin/activate

3. Install the requirements for both services.

At the time of writing, we have 2 services in Diffgram. The walrus service, and the default service. The walrus service is in charge of all the long running operations like media processing and the default service is the service for most of the backend API calls. We will install the dependencies for both below

pip install -r diffgram/default/requirements.txt 
pip install -r diffgram/walrus/requirements.txt

4. Set the Configuration file

In order for Diffgram to run correctly, we need to setup a set of values to the variables inside the file in the code. This can be done by either creating the enviornment variables, or, the recommended way for developers of diffgram, to use the file. This is a file that is not tracked on the repo where you can programatically set all the values for your variables. You can use the below example as a starting point.

touch diffgram/shared/settings/

Now open with your favorite code editor and paste this sample.

import os
import base64

running_locally = True

os.environ['DIFFGRAM_SYSTEM_MODE'] = DIFFGRAM_SYSTEM_MODE = "testing_e2e"  # "sandbox, production, staging, testing, testing_e2e

if DIFFGRAM_SYSTEM_MODE in ["testing_e2e", "testing"]:
    db_username = 'postgres'
    db_pass = "postgres"
    connector = "postgresql+psycopg2"
    db_name = "diffgram_e2e_tests"
    if DIFFGRAM_SYSTEM_MODE == 'testing':
        db_name = 'diffgram_testing'
    os.environ['EMAIL_DOMAIN_NAME'] = "localhost"
    # db_username = 'postgres'
    # db_pass = "postgres"
    # connector = "postgresql+psycopg2"
    # db_name = "diffgram"
    db_host = "localhost"
    os.environ['DATABASE_URL'] = connector + "://" + db_username + ":" + db_pass + "@" + db_host + "/" + db_name
    os.environ['EMAIL_VALIDATION'] = 'False'

    os.environ['USER_PASSWORDS_SECRET'] = 'secret'
    os.environ['DB_SECRET'] = 'secret'
    os.environ['SECRET_KEY'] = 'secret'
    os.environ['DIFFGRAM_AWS_ACCESS_KEY_ID'] = ''
    os.environ['DIFFGRAM_AWS_ACCESS_KEY_SECRET'] = ''
    os.environ['DIFFGRAM_S3_BUCKET_NAME'] = ''
    os.environ['ML__DIFFGRAM_S3_BUCKET_NAME'] = ''
    os.environ['WALRUS_SERVICE_URL_BASE'] = ""
    os.environ['DIFFGRAM_AZURE_CONNECTION_STRING'] = 'please set your connection string here'
    os.environ['DIFFGRAM_AZURE_CONTAINER_NAME'] = 'testdev'
    os.environ['ML__DIFFGRAM_AZURE_CONTAINER_NAME'] = 'testdev'
    os.environ['PROCESS_MEDIA_REMOTE_QUEUE_ON'] = 'True'
    os.environ['PROCESS_MEDIA_TRY_BLOCK_ON'] = 'False'
    os.environ['SERVICE_ACCOUNT_FULL_PATH'] = ''
    os.environ['GOOGLE_PROJECT_NAME'] = ''
    os.environ['CLOUD_STORAGE_BUCKET'] = ''
    os.environ['ML__CLOUD_STORAGE_BUCKET'] = ''

# Shared keys
os.environ['MAILGUN_KEY'] = ""
os.environ['INTER_SERVICE_SECRET'] = "secretsecret2872872kjashdkasjhsdas******aw"
os.environ['DIFFGRAM_INSTALL_FINGERPRINT'] = 'dev_pablo'
os.environ['DIFFGRAM_VERSION_TAG'] = 'development'
os.environ['DIFFGRAM_HOST_OS'] = 'dev'

We are assuming you have a local postgres installed on you machine with username postgres and password postrgres. You can modify` according to your needs. This is just an initial sample to get started and may not contain all the needed configurations values for full funcionality of diffgram.x

5. Start The Default Service

cd ./working-dir
export PYTHONPATH=/path/to/working-dir/diffgram/ 
cd diffgram/default

When you run the server you should see an error like this:

Traceback (most recent call last):
  File "", line 36, in <module>
  File "/home/pablo/testdiffgram/diffgram/default/", line 2, in do_routes_importing
    from methods.attribute.attribute_template_group import new_attribute_template_group_factory_api
  File "/home/pablo/testdiffgram/diffgram/default/methods/attribute/", line 1, in <module>
    from methods.regular.regular_api import *
  File "/home/pablo/testdiffgram/diffgram/default/methods/regular/", line 34, in <module>
    from shared.database.user import User
  File "/home/pablo/testdiffgram/diffgram/shared/database/", line 2, in <module>
    from shared.database.common import *
  File "/home/pablo/testdiffgram/diffgram/shared/database/", line 41, in <module>
    from shared import data_tools_core
  File "/home/pablo/testdiffgram/diffgram/shared/", line 31, in <module>
    data_tools = Data_tools().data_tools
  File "/home/pablo/testdiffgram/diffgram/shared/utils/", line 7, in __call__
    cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
  File "/home/pablo/testdiffgram/diffgram/shared/", line 28, in __init__
    self.data_tools = DataToolsAzure()
  File "/home/pablo/testdiffgram/diffgram/shared/", line 25, in __init__
    self.azure_service_client = BlobServiceClient.from_connection_string(settings.DIFFGRAM_AZURE_CONNECTION_STRING)
  File "/home/pablo/testdiffgram/venv3/lib/python3.7/site-packages/azure/storage/blob/", line 170, in from_connection_string
    account_url, secondary, credential = parse_connection_str(conn_str, credential, 'blob')
  File "/home/pablo/testdiffgram/venv3/lib/python3.7/site-packages/azure/storage/blob/_shared/", line 361, in parse_connection_str
    raise ValueError("Connection string is either blank or malformed.")

This is because we still require to set the DIFFGRAM_AZURE_CONNECTION_STRING to connect to an azure blob storage service. Please follow this link:

To learn more about how to generate one.

Once you generate you connection string run the above commands again and you should see something like this:

[2021-11-02 09:01:41,552] INFO Line 13: [default_service] Performing System Checks...
[2021-11-02 09:01:41,788] INFO Line 94: Checking for version upgrades [default_service]
Startup in 1.3195436000823975
 * Serving Flask app "Diffgram" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on (Press CTRL+C to quit)
 * Restarting with stat
[2021-11-02 09:01:42,770] INFO Line 13: [default_service] Performing System Checks...
[2021-11-02 09:01:43,004] INFO Line 94: Checking for version upgrades [default_service]

You have succesfully started the default service.

Other Storage Providers

You can also use aws or gcp as your static storage provider. Just change the DIFFGRAM_STATIC_STORAGE_PROVIDER to either aws or gcp and fill the following variables:

For aws:


For Gcp:

  • GOOGLE_PROJECT_NAME: The google project name
  • CLOUD_STORAGE_BUCKET: The bucket name on google storage.
  • SERVICE_ACCOUNT_FULL_PATH: The local path to your service account json file.

6. Start the Walrus Service

In A similar way you can now start the walrus service

cd ./working-dir
export PYTHONPATH=/path/to/working-dir/diffgram/ 
cd diffgram/walrus