- Notifications
You must be signed in to change notification settings - Fork0
Basis-Theory/python-sdk
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The BasisTheory Python library provides convenient access to the BasisTheory API from Python.
API reference documentation is availablehere.
pip install BasisTheoryClient
Instantiate and use the client with the following:
frombasis_theoryimportBasisTheoryclient=BasisTheory(api_key="YOUR_API_KEY",)client.tenants.self_.get()
The SDK also exports anasync
client so that you can make non-blocking calls to our API.
importasynciofrombasis_theoryimportAsyncBasisTheoryclient=AsyncBasisTheory(api_key="YOUR_API_KEY",)asyncdefmain()->None:awaitclient.tenants.self_.get()asyncio.run(main())
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following errorwill be thrown.
frombasis_theory.core.api_errorimportApiErrortry:client.tenants.self_.get(...)exceptApiErrorase:print(e.status_code)print(e.body)
Paginated requests will return aSyncPager
orAsyncPager
, which can be used as generators for the underlying object.
frombasis_theoryimportBasisTheoryclient=BasisTheory(api_key="YOUR_API_KEY",)response=client.applications.list()foriteminresponse:yielditem# alternatively, you can paginate page-by-pageforpageinresponse.iter_pages():yieldpage
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as longas the request is deemed retriable and the number of retry attempts has not grown larger than the configuredretry limit (default: 2).
A request is deemed retriable when any of the following HTTP status codes is returned:
Use themax_retries
request option to configure this behavior.
client.tenants.self_.get(..., {"max_retries":1})
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
frombasis_theoryimportBasisTheoryclient=BasisTheory( ...,timeout=20.0,)# Override timeout for a specific methodclient.tenants.self_.get(..., {"timeout_in_seconds":1})
You can override thehttpx
client to customize it for your use-case. Some common use-cases include support for proxiesand transports.
importhttpxfrombasis_theoryimportBasisTheoryclient=BasisTheory( ...,httpx_client=httpx.Client(proxies="http://my.test.proxy.example.com",transport=httpx.HTTPTransport(local_address="0.0.0.0"), ),)
While we value open-source contributions to this SDK, this library is generated programmatically.Additions made directly to this library would have to be moved over to our generation code,otherwise they would be overwritten upon the next generated release. Feel free to open a PR asa proof of concept, but know that we will not be able to merge it as-is. We suggest openingan issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!