Candid Python Library
The Candid Python library provides convenient access to the Candid APIs from Python.
Table of Contents
- Installation
- Reference
- Usage
- Async Client
- Exception Handling
- Oauth Token Override
- Advanced
- Contributing
Installation
pip install candidhealth
Reference
A full reference for this library is available here.
Usage
Instantiate and use the client with the following:
from candid import CandidApiClient
from candid.resources.pre_encounter.resources.coverages.resources.v_1 import (
MemberInfo,
)
from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
EligibilityRequest,
IndividualProvider,
)
client = CandidApiClient(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
client.pre_encounter.eligibility_checks.v_1.post(
request=EligibilityRequest(
payer_id="payer_id",
provider=IndividualProvider(
npi="npi",
),
subscriber=MemberInfo(
first_name="first_name",
last_name="last_name",
),
),
)
Async Client
The SDK also exports an async client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use httpx.AsyncClient() instead of httpx.Client() (e.g. for the httpx_client parameter of this client).
import asyncio
from candid import AsyncCandidApiClient
from candid.resources.pre_encounter.resources.coverages.resources.v_1 import (
MemberInfo,
)
from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
EligibilityRequest,
IndividualProvider,
)
client = AsyncCandidApiClient(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
async def main() -> None:
await client.pre_encounter.eligibility_checks.v_1.post(
request=EligibilityRequest(
payer_id="payer_id",
provider=IndividualProvider(
npi="npi",
),
subscriber=MemberInfo(
first_name="first_name",
last_name="last_name",
),
),
)
asyncio.run(main())
Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.
from candid.core.api_error import ApiError
try:
client.pre_encounter.eligibility_checks.v_1.post(...)
except ApiError as e:
print(e.status_code)
print(e.body)
Oauth Token Override
This SDK supports two authentication methods: OAuth client credentials flow (automatic token management) or direct bearer token authentication. You can choose between these options when initializing the client:
from candid import CandidApiClient
# Option 1: Direct bearer token (bypass OAuth flow)
client = CandidApiClient(..., token="my-pre-generated-bearer-token")
from candid import CandidApiClient
# Option 2: OAuth client credentials flow (automatic token management)
client = CandidApiClient(
..., client_id="your-client-id", client_secret="your-client-secret"
)
Advanced
Access Raw Response Data
The SDK provides access to raw response data, including headers, through the .with_raw_response property.
The .with_raw_response property returns a "raw" client that can be used to access the .headers and .data attributes.
from candid import CandidApiClient
client = CandidApiClient(
...,
)
response = client.pre_encounter.eligibility_checks.v_1.with_raw_response.post(
...
)
print(response.headers) # access the response headers
print(response.data) # access the underlying object
Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the max_retries request option to configure this behavior.
client.pre_encounter.eligibility_checks.v_1.post(..., request_options={
"max_retries": 1
})
Timeouts
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
from candid import CandidApiClient
client = CandidApiClient(
...,
timeout=20.0,
)
# Override timeout for a specific method
client.pre_encounter.eligibility_checks.v_1.post(..., request_options={
"timeout_in_seconds": 1
})
Custom Client
You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies
and transports.
import httpx
from candid import CandidApiClient
client = CandidApiClient(
...,
httpx_client=httpx.Client(
proxy="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)
Contributing
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 as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
Metadata
Release files for candidhealth 1.37.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| candidhealth-1.37.0.tar.gz | 668.3 kB | Without provenance | Details for candidhealth-1.37.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| candidhealth-1.37.0-py3-none-any.whl | Python 3 | none | any | Details for candidhealth-1.37.0-py3-none-any.whl |
Total release size: 2.2 MB
Release files / candidhealth-1.37.0.tar.gz
| Download URL | candidhealth-1.37.0.tar.gz |
|---|---|
| Size | 668.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
919a5194c43d889ff99a95ec63d249e091e3a8274e44d8342521c4731ddca0e2
|
|
BLAKE2b-256 checksum How to use checksums |
d7b5f7bca0b605f550ca6d6a0e4a6deba1991fd76a03905a0478bdf1a8d27951
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.18 Linux/6.17.0-1022-azure
|
Release files / candidhealth-1.37.0-py3-none-any.whl
| Download URL | candidhealth-1.37.0-py3-none-any.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3bc9baa16ffd709840d1e4daffaf23138b47e48ddc0522aa2158eef4363ed8be
|
|
BLAKE2b-256 checksum How to use checksums |
5b01b36ae3cf0b7cd4faee9514b8f5c0696d49c2573cf5b7cc76391f239f3bc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.18 Linux/6.17.0-1022-azure
|
Security for candidhealth 1.37.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.