Python SDK setup and configuration
Learn about Quickstart and how you can use it to quickly set up and run eSignature REST API code examples.
Adding the SDK to your project
The Python eSignature SDK is provided as a PyPI module named docusign-esign. By default, you will always get the latest stable version of the SDK. Prerelease versions (either release candidate (RC) or beta) can also be downloaded, as we’ll show later.
There are two ways to add the package to your project: via the command line or by downloading the SDK from GitHub.
Adding the SDK to your project using the command line
- In your command console, input:
pip install docusign-esign
Downloading the SDK from the GitHub repository
The SDK is provided as an open-source library for cases where you would like to make additional changes that are not provided out of the box. You can download the SDK from GitHub using the instructions below:
-
Go to the Python SDK GitHub repository.
-
Select the green Code button. From here, you can clone the repo, open it in GitHub Desktop, or download it as a ZIP, which you can install to a path of your choice.
Locate your Python installation. This folder is usually labeled in a format of Python{VersionNumber}.
Examples:
- Unix/Linux: /usr/lib/python3.8
- Mac: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
- Windows: C:\Users{username}\AppData\Local\Programs\Python\Python37
- Inside your Python folder you will find a site-packages folder. Make sure that your newly downloaded Python SDK is inside that site-packages folder.
- Add the path to your Python folder as an environment variable. You can skip this step if you have already set up the appropriate PYTHONPATH variable.
Including the SDK library
Once you have installed the PyPI module, you need to find the public classes that are needed to complete various eSignature tasks. To do that, you will use import statements to add any classes that you need to your code. The three most commonly required namespaces that you will be importing from are
docusign_esign,
docusign_esign.models, and
docusign_esign.client.
docusign_esign.apis module
This Python SDK module contains endpoint categories. Each class under this module corresponds to one of the categories listed in the left menu of the Docusign eSignature REST API reference. You will need to use this namespace to make calls to SDK methods that initiate REST API calls to the Docusign eSignature REST API.
An API category contains all of the methods for each API resource in that category. For example, the Python SDK EnvelopesApi class includes the create_envelope method. This method corresponds to the API Envelopes resource create method.
The SDK’s method names roughly correspond to the API Resource:method names.
The API reference page for each endpoint lists the corresponding SDK method associated with that endpoint. To find the Python SDK method that corresponds to an API Resource:method page, use the API reference page’s
SDK Method box. The Python method name will be the “snake_case” version of the API SDK Method name. For example, the API SDK Method
Envelopes::createEnvelope is the Python SDK method
create_envelope.
docusign_esign.models module
This module contains the objects used for sending and receiving data from the eSignature API endpoints. By using these classes instead of generic JSON objects, Python developers can develop with the Docusign eSignature API much more easily and quickly than by using JSON directly.
There is a one-to-one correspondence between the objects described in the API reference and the classes in the docusign_esign.models module. The API object names use camelCase (the first letter is lowercase) while the corresponding SDK models use PascalCase (the first letter is uppercase). For example, the API object paymentgatewayaccount corresponds to the Python object PaymentGatewayAccount.
Note: The API object name is often not the same as the corresponding model in the Python SDK.
Object attribute names in the API also use camelCase. The corresponding properties of the Python SDK classes are in “snake_case.”
Some API endpoints also use HTTP query parameters. Within the API, the query parameters use “snake_case.” For example, the
Envelopes:create API method includes an optional query parameter
change_routing_order. Within the SDK, the API’s query parameters are added as an optional
**kwargs parameter after the request object.
Example: The
EnvelopesApi.create_envelope function takes three parameters:
self,
account_id, and
**kwargs.
When calling the function, you might need to pass an EnvelopeDefinition object as one of the arguments. To do this, you would create an EnvelopeDefinition object named
new_envelope and pass it as
envelope_definition=new_envelope.
docusign_esign.client module
This namespace contains the classes needed to manage the overall API experience. These include the classes needed to instantiate a client element to make API calls and the classes used for authentication and exception handling. You will need to include this namespace to be able to use the Docusign eSignature API correctly.
Using the SDK
To make eSignature REST API calls with the SDK, you need:
- A current access token
- The base path for the API call
- For most API calls, you’ll also need the relevant
account_id. Note that it is common for a user to be a member of multiple accounts.