Skip to main content

Simple DocuSign client for Flask

Project description



This package allows easy integrate your Flask application with DocuSign API.

The package is using impersonated user aka JWT Grant as integration mode.


pip install flask-docusign


Step 1. Grant permissions

Before using DocuSign API through impersonated user you have to grant permissions for your application to do this. For this you have to execute the next query in your browser:

In the example above, we are using demo account, that's why we use domain. For your production account you could use

Please, note that YOUR_REDIRECT_URI should be registered in the platform.

Callbacks example

YOUR_INTEGRATOR_KEY can be found as well on settings page of your project.

Integration key example

In case of correct call you will see the next page (in my case it is in Ukrainian) and after approving your application will be able to use DocuSign API.

Integration key example

Step 2. Configure your application

The package expects configuration parameters to be passed inside dictionary like object. Next config variables are required:

# Base URL should be different on production -
BASE_URL = os.getenv('DS_BASE_URL', '')
APP_URL = "http://localhost:8080"

BASE_URI_SUFFIX = "/restapi"

# How get template id is described below

# The app's DocuSign integration key
DS_CLIENT_ID = os.getenv('DS_CLIENT_ID')

# Application secret


# For demo accounts -,
# for production accounts -

# The id of the user.

# RSA key generated by DocuSign platform

How get you credentials

In admin console go on tab Settings, then select App and keys

  1. Get impersonated user id and integration key. You can get impersonated user id from App and keys page. Integration key will be listed for every project as well.

Impersonated user id example

  1. Get external application user id (DS_EXT_APP_USER_ID). In the top right click on your avatar and you will see the next modal window:

External application user user id example

  1. Application secret (DS_CLIENT_SECRET) and private key file (PRIVATE_KEY_FILE) you can get from you application page. For this purpose click on Actions select menu and select Edit then in Authentication you can generate secret key for your application. In Service Integration you have to generate RSA. Important! When you provide RSA key as environment variable you have to preserve RSA structure with '\n' (separating every new row) in other case Python will fail to parse it.

Step 3. Your DocuSign template

You have to upload a document template which users will sign. When your document will be uploaded you can get it's template id. Usually template id can be taken from URL in a browser address line or from 'Template ID' link:

Template id example

Then you have to define recipient role for you template. For this you have to press 'Edit' button on the template's page. Then you will see the next:

Add recipient example

Usually it doesn't make a sense to specify name or email, so we come with role only. In my case I use 'signer' role name. You can specify role name you like.

Step 4. Define request handling logic

Request handling endpoints look very simple when you use the package. Here is an example:

@ds.route('/', methods=['POST'])
def docusign_create_envelope():
    """Creates envelope and submits it to DocuSign, as response 
    receives signing URL for user to follow.
    config = current_app.config
    msg, status = create_envelope(config, request, session)
    return jsonify({'msg': msg}), status

def ds_callback():
    Save the token information in session.
    Call api to get user's information if it doesn't present.
    # Save the redirect eg if present
    config = current_app.config
    set_client_cookie(config, session)
    return redirect('docusign_create_envelope')

@ds.route("/check/<envelope_id>", methods=['GET'])
def ds_check_envelope(envelope_id):
    """Check signing state."""
    state = 401
    if not len(envelope_id):
        return jsonify({'msg': 'Please verify your envelope id.'}), state
    config = current_app.config
    response, state = check_envelope(config, session, envelope_id)
    return jsonify({'msg': response}), state

Example application can be found in example folder.

You can run example application with your DocuSign project credentials. Post request on http://localhost:8080/ds/ with payload:

    "phone_number": "+491111111111111",
    "full_name": "Arnrn Bcd",
    "client_user_id": "1234567",
    "email": ""

should return response similar to:

    "msg": {
        "envelopeId": "59840612-14a8-45fd-83ad-82aaaaaaaaaa",
        "url": ""

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-docusign-0.1.2.tar.gz (11.7 kB view hashes)

Uploaded source

Built Distribution

flask_docusign-0.1.2-py3-none-any.whl (10.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page