Package: currencycloud
currencycloud-pythonCurrency CloudThis is the official Python SDK for v2 of Currency Cloud’s API.
Additional documentation for each API endpoint can be found atconnect.currencycloud.com.
If you have any queries or you require support, please contact our
implementation team atimplementation@currencycloud.com.The full source code, tests and examples can be always found ongithub.InstallationWe supports installation using standard Python “distutils” or
“setuptools” methodologies. An overview of potential setups is as
follows:Plain Python Distutis- The library can be installed with a clean
Python install using the services provided via Python Distutils,
using the setup.py script.Setuptools or Distribute- When usingsetuptools, the
library can be installed via setup.py or easy_install.pip-pipis an installer
that rides on top of setuptools or distribute, replacing the usage of
easy_install. It is often preferred for its simpler mode of usage.Install via pipWhen pip is available, the distribution can be downloaded from PyPi and
installed in one step:pip install currencycloudThis command will download the latest released version of the library
from the Python Cheese Shop and install it to your system.Install using setup.pyOtherwise, you can install from the distribution using the setup.py
script:python setup.py installSupported Python versionsThis library aims to support and istested
againstthe
following Ruby implementations:CPython 2.6CPython 2.7CPython 3.2CPython 3.3CPython 3.4pypyUsage>>>importcurrencycloud## Configure ##>>>currencycloud.login_id='<your login id>'>>>currencycloud.api_key='<your api key>'>>>currencycloud.environment=currencycloud.ENV_DEMOSTRATION# use currencycloud.ENV_PRODUCTION when ready## Make API calls ##>>>currencies=currencycloud.Reference.currencies()>>>currencies[<currencycloud.resources.reference.Currencyobjectat0x10e6fd190>,<currencycloud.resources.reference.Currencyobjectat0x10e6fd1d0>,<currencycloud.resources.reference.Currencyobjectat0x10e6fd2d0>,…<currencycloud.resources.reference.Currencyobjectat0x10e6fd9d0>]>>>balances=currencycloud.Balance.find()>>>balances[<currencycloud.resources.balance.Balanceobjectat0x10e6fd7d0>]>>>balances.paginationAttrDict({u'next_page':-1,u'previous_page':-1,u'total_entries':1,u'current_page':1,u'total_pages':1,u'order_asc_desc':u'asc',u'per_page':25,u'order':u'created_at'})>>>balances[0].currencyu'GBP'>>>currency_usd=balances[0].currency_with_code('USD')>>>currency_usd<currencycloud.resources.balance.Balanceobjectat0x10cddcc50>## Access attributes ##>>>currency_usd.currencyu'USD'>>>currency_usd['currency']u'USD'On Behalf OfIf you want to make calls on behalf of another user (e.g. someone who
has a sub-account with you), you can execute certain commands ‘on behalf
of’ the user’s contact_id. Here is an example:withcurrencycloud.on_behalf_of('c6ece846-6df1-461d-acaa-b42a6aa74045'):beneficiary=currencycloud.Beneficiary.create(<params>)conversion=currencycloud.Conversion.create(<params>)payment=currencycloud.Payment.create(<params>)Alternatively, you can just addon_behalf_ofto the call parameters,
for example:currencycloud.Account.create(account_name='My Test User',on_behalf_of='c6ece846-6df1-461d-acaa-b42a6aa74045')Each of the above transactions will be executed in scope of the permissions
for that contact and linked to that contact. Note that the real user who
executed the transaction will also be stored.ErrorsWhen an error occurs in the API, the library aims to give us much
information as possible. Here is an example:BadRequestError---errors:-code:term_agreement_is_requiredfield:term_agreementmessage:term_agreement is requiredparams:{}-code:term_agreement_type_is_wrongfield:term_agreementmessage:term_agreement should be of boolean typeparams:type:booleanplatform:python - 2.7.6 (default, Sep  9 2014, 15:04:36) - CPythonrequest:parameters:amount:-'1000'buy_currency:-GBPfixed_side:-buyreason:-mortagesell_currency:-USDurl:https://devapi.thecurrencycloud.com/v2/conversions/createverb:postresponse:date:Thu, 25 Jun 2015 16:46:42 GMTrequest_id:2816384323363505615status_code:400This is split into 5 sections:Error Type: In this caseBadRequestErrorrepresents an HTTP 400
errorPlatform: The Python implementation that was used e.g. ‘python -
2.7.6’Request: Details about the HTTP request that was made e.g. the POST
parametersResponse: Details about the HTTP response that was returned e.g. HTTP
status codeErrors: A list of errors that provide additional informationThe errors section contains valuable information:Field: The parameter that the error is linked toCode: A code representing this errorMessage: A human readable message that explains the errorParams: A hash that contains dynamic parts of the error message for
building custom error messagesWhen troubleshooting API calls with Currency Cloud support, including
the full error in any correspondence can be very helpful.DevelopmentTo run the test cases we usetox, a generic virtualenv
management and test command line tool. It can be easily installed withpippip install toxor withsetuptoolseasy_install toxTo run the teststoxDependenciesrequestspyYAMLattrdictVersioningThis project usessemantic versioning. You can
safely express a dependency on a major version and expect all minor and
patch versions to be backwards compatible.CopyrightCopyright (c) 2015 Currency Cloud. SeeLICENSEfor
details.