Python
dwollav2 is available on PyPi with
source code available on our GitHub page.
Getting Started
Installation
To begin using this SDK, you will first need to download it to your machine. We use PyPi to distribute this package from where you can automagically download it via pip.Initialization
Before any API requests can be made, you must first determine which environment you will be using, as well as fetch the application key and secret. To fetch your application key and secret, please visit one of the following links:- Production: https://dashboard.dwolla.com/applications
- Sandbox: https://dashboard-sandbox.dwolla.com/applications
Client with key and secret replaced with the application key and secret that you fetched from one of the aforementioned links, respectively.
Configure an on_grant callback (optional)
An on_grant callback is useful for storing new tokens when they are granted. The on_grant
callback is called with the Token that was just granted by the server.
Tokens
Generating New Access Tokens
Application access tokens are used to authenticate against the API on behalf of an application. Application tokens can be used to access resources in the API that either belong to the application itself (webhooks, events, webhook-subscriptions) or the Dwolla Account that owns the application (accounts, customers, funding-sources, etc.). Application tokens are obtained by using the client_credentials OAuth grant type:
refresh_token. When it expires, generate a new one using client.Auth.client().
Initializing Pre-Existing Tokens:
The Dwolla Sandbox Dashboard allows you to generate tokens for your application. AToken can be initialized with the following attributes:
Making Requests
Once you’ve created aToken, currently, you can make low-level HTTP requests.
Low-level Requests
To make low-level HTTP requests, you can use theget(), post(), and delete() methods. These methods will return a Response object.
GET
POST
DELETE
Setting headers
To set additional headers on a request you can pass adict of headers as the 3rd argument.
For example:
Responses
The following snippets demonstrate successful and errored responses from the Dwolla API. An errored response is returned when Dwolla’s servers respond with a status code that is greater than or equal to 400, whereas a successful response is when Dwolla’s servers respond with a 200-level status code.Success
Error
If the server returns an error, adwollav2.Error (or one of its subclasses) will be raised.
dwollav2.Errors are similar to Responses.
dwollav2.Error subclasses:
See https://developers.dwolla.com/api-reference#errors for more info.
dwollav2.AccessDeniedErrordwollav2.InvalidCredentialsErrordwollav2.NotFoundErrordwollav2.BadRequestErrordwollav2.InvalidGrantErrordwollav2.RequestTimeoutErrordwollav2.ExpiredAccessTokenErrordwollav2.InvalidRequestErrordwollav2.ServerErrordwollav2.ForbiddenErrordwollav2.InvalidResourceStateErrordwollav2.TemporarilyUnavailableErrordwollav2.InvalidAccessTokenErrordwollav2.InvalidScopeErrordwollav2.UnauthorizedClientErrordwollav2.InvalidAccountStatusErrordwollav2.InvalidScopesErrordwollav2.UnsupportedGrantTypeErrordwollav2.InvalidApplicationStatusErrordwollav2.InvalidVersionErrordwollav2.UnsupportedResponseTypeErrordwollav2.InvalidClientErrordwollav2.MethodNotAllowedErrordwollav2.ValidationErrordwollav2.TooManyRequestsErrordwollav2.ConflictError
Example App
Take a look at the Sample Application for examples on how to use this SDK to call the Dwolla API. Before you can begin using the app, however, you will need to specify aDWOLLA_APP_KEY and DWOLLA_APP_SECRET environment variable.
Community
- If you have any feedback, please reach out to us on our forums or by creating a GitHub issue.
- If you would like to contribute to this library, bug reports and pull requests are always appreciated!
- After checking out the repo, run
pip install -r requirements.txtto install dependencies. Then, runpython setup.pytest to run the tests. - To install this gem onto your local machine,
run pip install -e ..
- After checking out the repo, run