Package: dwollav2
DwollaV2Dwolla V2 Python client.API DocumentationInstallationdwollav2is available onPyPi, and therefore can be installed automagically viapip.pip install dwollav2dwollav2.ClientBasic usageCreate a client using your application's consumer key and secret found on the applications page
(Sandbox,Production).client=dwollav2.Client(key=os.environ['DWOLLA_APP_KEY'],secret=os.environ['DWOLLA_APP_SECRET'],environment='sandbox',# defaults to 'production'requests={'timeout':0.001})Configure anon_grantcallback (optional)Anon_grantcallback is useful for storing new tokens when they are granted. Theon_grantcallback is called with theTokenthat was just granted by the server.client=dwollav2.Client(key=os.environ['DWOLLA_APP_KEY'],secret=os.environ['DWOLLA_APP_SECRET'],on_grant=lambdat:save(t))It is highly recommended that you encrypt any token data you store.Integrations AuthorizationCheck out ourIntegrations Authorization Guide.TokenTokens can be used to make requests to the Dwolla V2 API.Application tokensApplication access tokens are used to authenticate against the API on behalf of a consumer 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 partner Account that owns the consumer application (accounts,customers,funding-sources, etc.). Application tokens are obtained by using theclient_credentialsOAuth grant type:application_token=client.Auth.client()Application tokens do not include arefresh_token. When an application token expires, generate
a new one usingclient.Auth.client().Initializing pre-existing tokens:Tokens can be initialized with the following attributes:client.Token(access_token='...',expires_in=123)RequestsTokens can make requests using the#get,#post, and#deletemethods.# GET api.dwolla.com/resource?foo=bartoken.get('resource',foo='bar')# POST api.dwolla.com/resource {"foo":"bar"}token.post('resource',foo='bar')# POST api.dwolla.com/resource multipart/form-data foo=...token.post('resource',foo=('mclovin.jpg',open('mclovin.jpg','rb'),'image/jpeg'))# PUT api.dwolla.com/resource {"foo":"bar"}token.put('resource',foo='bar')# DELETE api.dwolla.com/resourcetoken.delete('resource')Setting headersTo set additional headers on a request you can pass adictof headers as the 3rd argument.For example:token.post('customers',{'firstName':'John','lastName':'Doe','email':'jd@doe.com'},{'Idempotency-Key':'a52fcf63-0730-41c3-96e8-7147b5d1fb01'})ResponsesRequests return aResponse.res=token.get('/')res.status# => 200res.headers# => {'server'=>'cloudflare-nginx', 'date'=>'Mon, 28 Mar 2016 15:30:23 GMT', 'content-type'=>'application/vnd.dwolla.v1.hal+json; charset=UTF-8', 'content-length'=>'150', 'connection'=>'close', 'set-cookie'=>'__cfduid=d9dcd0f586c166d36cbd45b992bdaa11b1459179023; expires=Tue, 28-Mar-17 15:30:23 GMT; path=/; domain=.dwolla.com; HttpOnly', 'x-request-id'=>'69a4e612-5dae-4c52-a6a0-2f921e34a88a', 'cf-ray'=>'28ac1f81875941e3-MSP'}res.body['_links']['events']['href']# => 'https://api-sandbox.dwolla.com/events'ErrorsIf the server returns an error, adwollav2.Error(or one of its subclasses) will be raised.dwollav2.Errors are similar toResponses.try:token.get('/not-found')exceptdwollav2.NotFoundErrorase:e.status# => 404e.headers# => {"server"=>"cloudflare-nginx", "date"=>"Mon, 28 Mar 2016 15:35:32 GMT", "content-type"=>"application/vnd.dwolla.v1.hal+json; profile=\"http://nocarrier.co.uk/profiles/vnd.error/\"; charset=UTF-8", "content-length"=>"69", "connection"=>"close", "set-cookie"=>"__cfduid=da1478bfdf3e56275cd8a6a741866ccce1459179332; expires=Tue, 28-Mar-17 15:35:32 GMT; path=/; domain=.dwolla.com; HttpOnly", "access-control-allow-origin"=>"*", "x-request-id"=>"667fca74-b53d-43db-bddd-50426a011881", "cf-ray"=>"28ac270abca64207-MSP"}e.body.code# => "NotFound"exceptdwollav2.Error:# ...dwollav2.Errorsubclasses:Seehttps://docsv2.dwolla.com/#errorsfor 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.ConflictErrorDevelopmentAfter checking out the repo, runpip install -r requirements.txtto install dependencies.
Then, runpython setup.py testto run the tests.To install this gem onto your local machine, runpip install -e ..ContributingBug reports and pull requests are welcome on GitHub athttps://github.com/Dwolla/dwolla-v2-python.LicenseThe package is available as open source under the terms of theMIT License.Changelog2.2.1Add extra check in URL's to ensure they are clean.#36.2.2.0Update JSON request bodies to serialize viasimplejsonso datatypes likeDecimalstill
serialize like they did pre2.0.02.1.0Do not sharerequests.session()across instances ofdwollav2.Client2.0.0JSON request bodies now contain sorted keys to ensure the same request body for a given set of
arguments, no matter the order they are passed todwolla.post. This ensures theIdempotency-Keyheader will work as intended without additional effort by developers.NOTE: Because this change alters the formatting of JSON request bodies, we are releasing it
as a major new version. The request body of a request made with1.6.0will not match the
request body of the same request made in2.0.0. This will nullify the effect of theIdempotency-Keyheader when upgrading, so please take this into account.
If you have any questions pleasereach out to us!
There are no other changes since1.6.0.1.6.0Allow configuration ofrequestsoptions ondwollav2.Client.1.5.0Add integrations auth functionality1.4.0Pass kwargs fromget,post, anddeletemethods to underlying requests methods.(Removed in v1.6)1.3.0Change token URLs, update dependencies.1.2.4Create a new session for each Token.1.2.3Check if IOBase when checking to see if something is a file.1.2.2Strip domain from URLs provided to token.* methods.1.2.1Update sandbox URLs from uat => sandbox.1.2.0Refer to Client id as key.1.1.8Supportverified_accountanddwolla_landingauth flags1.1.7Use session over connections forperformance improvement(#8- Thanks @bfeeser!)1.1.5Fix file upload bug when using with Python 2 (#6)1.1.2AddTooManyRequestsErrorandConflictError1.1.1Add MANIFEST.in1.1.0Support per-request headers