Package: postmen
IntroductionPython SDK forPostmen API. For problems
and suggestions please openGitHub
issueTable of ContentsInstallationQuick Startclass PostmenPostmen(api_key, region, **kwargs)create(self, resource, payload, **kwargs)get(self, resource, id_=None, **kwargs)getError()GET(self, path, **kwargs)POST(self, path, **kwargs)PUT(self, path, **kwargs)DELETE(self, path, **kwargs)Error Handlingclass PostmenExceptionAutomatic retry on retryable
errorExamplesFull listHow to runNavigation tableTestingLicenseContributorsInstallationManualDownload or clone this repo, then runpython setup.py installPyPIRunpip install postmenQuick StartIn order to get API key and choose a region refer to thedocumentation.importpprintpp=pprint.PrettyPrinter(indent=4)frompostmenimportPostmen,PostmenExceptionapi_key='YOUR_API_KEY'region='sandbox'# create Postmen API handler objectapi=Postmen(api_key,region)try:# as an example we request all the labelsresult=api.get('labels')print("RESULT:")pp.pprint(result)exceptPostmenExceptionase:# if error occurs we can access all# the details in following wayprint("ERROR")print(e.code())# error codeprint(e.message())# error messagepp.pprint(e.details())# detailsclass PostmenPostmen(api_key, region, **kwargs)Initiate Postmen SDK object. In order to get API key and choose a region
refer to thedocumentation.ArgumentRequiredTypeDefaultDescriptionapi_keyYESStringN / AAPI keyregionNO ifendpointis setStringN / AAPI region (sandbox,production)endpoint—StringN / ACustom URL API endpointretry—BooleanTrueAutomatic retry on retryable errorsrate—BooleanTrueWait before API call if
rate limit exceeded or
retry on 429 errorsafe—BooleanFalseSuppress exceptions on
errors, None would be
returned instead, checkError Handlingraw—BooleanFalseTo return API response as a raw stringproxy—Dictionary{}Proxy credentials,
handled as inrequests
librarytime—BooleanFalseConvert ISO time strings
intodatetimeobjectscreate(self, resource, payload, **kwargs)Creates APIresourceobject, returns new object payload asDictionary.ArgumentRequiredTypeDefaultDescriptionresourceYESStringN / APostmen API resourse (‘rates’,
‘labels’, ‘manifests’)payloadYESArray or
StringN / APayload according to API**kwargsNONamed
argumentsN / AOverride constructorconfigAPI Docs:POST /ratesPOST /labelsPOST /manifestsPOST /cancel-labelsExamples:rates_create.pylabels_create.pymanifests_create.pycancel_labels_create.pyget(self, resource, id_=None, **kwargs)Gets API$resourceobjects (list or a single objects).ArgumentRequiredTypeDefaultDescriptionresourceYESStringN / APostmen API resourse (‘rates’,
‘labels’, ‘manifests’)idNOStringNoneObject ID, if not set ‘list all’ API
method is usedqueryNODictionary or
StringN / AHTTP GET query (named argument)**kwargsNONamed
argumentsN / AOverride constructorconfigAPI Docs:GET /ratesGET /rates/:idGET /labelsGET /labels/:idGET /manifestsGET /manifests/:idGET /cancel-labelsGET /cancel-labels/:idExamples:rates_retrieve.pylabels_retrieve.pymanifests_retrieve.pycancel_labels_retrieve.pygetError()Returns SDK error,PostmenException typeif named argumentsafe = Truewas set.CheckError Handlingfor details.GET(self, path, **kwargs)Performs HTTP GET request, returns anDictionaryobject holding API
response.ArgumentRequiredTypeDefaultDescriptionpathYESStringN / AURL path (e.g. ‘v3/labels’ forhttps://sandbox-api.postmen.com/v3/labels)queryNODictionary or
StringN / AHTTP GET query (named argument)**kwargsNONamed
argumentsarray ()query, and other values
overriding constructorconfigPOST(self, path, **kwargs)PUT(self, path, **kwargs)DELETE(self, path, **kwargs)Performs HTTP POST/PUT/DELETE request, returns aDictionaryobject
holding API response.ArgumentRequiredTypeDefaultDescriptionpathYESStringN / AURL path (e.g. ‘v3/labels’ forhttps://sandbox-api.postmen.com/v3/labels)bodyNODictionary or
StringN / AHTTP POST/PUT/DELETE request body
(named argument)**kwargsNONamed
argumentsN / AOverride constructorconfigError HandlingParticular error details are listed in thedocumentation.All SDK methods may throw an exception described below.class PostmenExceptionMethodReturn
typeDescriptioncode()IntegerError coderetryable(
)BooleanIndicates if error is retryablemessage()StringError message (e.g.The request was invalid or cannot be otherwise ser ved)details()ListError details (e.g.Destination country must be RUS or KAZ)In case ofsafe = TrueSDK would not throw exceptions,getError()must be used instead.Example:error.pyAutomatic retry on retryable errorIf API error is retryable, SDK will wait for delay and retry. Delay
starts from 1 second. After each try, delay time is doubled. Maximum
number of attempts is 5.To disable this option setretry = FalseExamplesFull listAll examples avalible listed in the table below.FileDescriptionrates_create.pyratesobject creationrates_retrieve.pyratesobject(s) retrievelabels_create.pylabelsobject creationlabels_retrieve.pylabelsobject(s) retrievemanifests_create.pymanifestsobject creationmanifests_retrieve.pymanifestsobject(s) retrievecancel_labels_create.pycancel-labelsobject creationcancel_labels_retrieve.pycancel-labelsobject(s) retrieveproxy.pyProxy usageerror.pyAvalible ways to catch/get errorsHow to runDownload the source code, go toexamplesdirectory.If you already installed Postmen SDK for Python you can proceed,
otherwise install it by runningpython setup.py installor using
PyPI.Put your API key and region tocredentials.pyCheck the file you want to run before run. Some require you to set
additional variables.Navigation tableFor each API method SDK provides Python wrapper. Use the table below to
find SDK method and example that match your need.Model \ Actioncreateget allget by idrates.create(‘rates’, payload).get(‘rates’).get(‘rates’, id)labels.create(‘labels’, payload).get(‘labels’).get(‘labels’, id)manifests.create(‘manifests’, payload).get(‘manifests’).get(‘manifests’, id)cancel-labels.create(‘cancel-labels’, payload).get(‘cancel-labels’).get(‘cancel-labels’, id)TestingIf you contribute to SDK, run automated test before you make pull
request.pip install -r requirements.txt
python setup.py testLicenseReleased under the MIT license. See the LICENSE file for details.ContributorsFedor Korshunov -view
contributionsMarek Narozniak -view
contributions