Python SDK
Install the official Python SDK and connect your backend to the Raims public API.
Use the raims package in your integration backend, with synchronous and asynchronous clients, typed parameters, read-only responses, cursor pagination, and webhook authentication.
Install the package
The SDK requires Python 3.10 or later. In your application's virtual environment:
python -m pip install raimsThe raims package is on PyPI and keeps the
same import name. Pip resolves its dependencies. Check the
release history and pin the version you
choose in your application's requirements.txt or lockfile.
Download the wheel
and SHA256SUMS
to a raims-python-release directory. The browser saves the wheel using its
full versioned filename; keep that name and verify the hash before installing.
Choose the shell used by your application; keep exactly one downloaded wheel in this directory.
python -m pip install ./raims-python-release/raims-*.whl$wheels = @([System.IO.Directory]::GetFiles((Resolve-Path ./raims-python-release).Path, '*.whl'))
if ($wheels.Count -ne 1) { throw 'Keep exactly one downloaded wheel in this directory.' }
python -m pip install $wheels[0]Configure the client
Prepare the credential
Get a key from API keys and store it in a vault or protected application environment variable. Keep the credential in the backend, out of browsers, applications distributed to customers, and logs.
The validated API key determines company, environment, and permissions. Sandbox and Production use
https://api.raims.com.For this first read, use a Sandbox key with View customers permission. The request only reads one page; it does not create customers or request emails.
Save the read example
read_customers.py Pythonimport os from raims import ApiError, ConnectionError, RaimsClient api_key = os.environ["RAIMS_API_KEY"] with RaimsClient(api_key, max_network_retries=0) as raims: try: customers = raims.customers.list({"page_size": 10}) print(f"HTTP status: {customers.last_response.status_code}; items: {len(customers)}") except ApiError as error: print(f"HTTP status: {error.status_code}; code: {error.code}; Request-Id: {error.request_id}") raise SystemExit(1) from None except ConnectionError: print("Read failed before a conclusive response. Check the connection.") raise SystemExit(1) from NoneRun and check the result
From the project directory, with
RAIMS_API_KEYavailable to the process, run:Shellpython read_customers.pyA successful read prints
HTTP status: 200and the number of items in this page.items: 0is a valid empty result for the key’s company and environment. It is not an authentication failure.
What to check
The SDK reads the list and page envelope below. In an empty page, has_next: false means there is no next page. A nonempty page also returns customer records; the program prints only their count.
No customers found
{
"list": [],
"page": {
"page_size": 10,
"has_next": false,
"has_previous": false,
"next_after": null,
"previous_before": null
}
}Reuse the client for its intended lifecycle. with closes the synchronous client; for asynchronous use, choose AsyncRaimsClient with async with and await on calls. Keep one asynchronous instance per event loop lifecycle.
Create a customer and a charge
This is a backend snippet, after loading the order from your application’s storage. Keep the customer key separate from the charge key. Save the entire request payload, including the amount and title, before sending; read it again on retries instead of generating new values.
| Input from the saved order | Source and purpose |
|---|---|
customer_tax_id | Customer tax ID already authorized and saved by your application. |
customer_idempotency_key | Idempotency key for creating this customer; saved before the first request. |
charge_idempotency_key | A different idempotency key for this charge; saved with the order. |
charge_due_date | Chosen due date, saved in UTC Unix seconds. |
from raims import RequestOptions
with RaimsClient(api_key) as raims:
customer = raims.customers.create(
{"tax_id": customer_tax_id},
options=RequestOptions(idempotency_key=customer_idempotency_key),
)
charge = raims.charges.create(
{
"customer_id": customer.id,
"amount_cents": 15000,
"due_date": charge_due_date,
"title": "Pedido 1234",
},
options=RequestOptions(idempotency_key=charge_idempotency_key),
)
charge_id = charge.id
response = charge.last_response
pending = response is not None and response.status_code == 202Persist the returned customer ID and charge ID on the order before returning success to your caller. The charge ID is the value used to resume the read below; the SDK variables are not durable storage.
| Result | What to do next |
|---|---|
HTTP 201 | The charge was created. Save its ID; creation does not confirm payment. This snippet does not request email or payment issuance. |
HTTP 202 in a creation that requests payment issuance | Save the same returned ID and keep the order pending. Retrieve that charge; do not create another one to resolve the pending result. |
| Error or missing response | Handle the structured error. If execution is uncertain, keep the intent and reconcile before retrying with the original key and payload. |
The canonical creation example below shows only the ID and status fields:
Charge without a link or email request
{
"id": "ch_1Q2W3E4R5T6Y7U8I9O0P",
"status": 0
}If the CPF or CNPJ already exists in the same company and environment, the customer is updated and keeps its identifier. 15000 represents BRL 150.00. Keep the key and every parameter, including the due date, when recovering the same intent after losing a response. See Create a charge.
Inputs retain the API JSON names. Omitting a key leaves the field absent; None sends null. Check the contract before clearing a value. Responses preserve future fields and should not be changed directly.
Pagination and pending results
list() fetches one page. Normal iteration reads only the received items; next_page() and previous_page() preserve filters. auto_paging_iter() loads subsequent pages as you consume it. With the asynchronous client, use await for the query and async for for the iterator.
The following backend snippet counts at most 100 customers across pages, without logging their records. Keep the configured client open during iteration.
with RaimsClient(api_key) as raims:
page = raims.customers.list({"page_size": 50})
visited = 0
for customer in page.auto_paging_iter():
visited += 1
if visited == 100:
break
print(f"Items visited: {visited}")Items visited: 0 means the query found no customers. 100 means the chosen limit was reached; it does not prove there are no more records. A page error interrupts the count. Save progress only after processing a complete page if your job must resume later.
Copy the received cursors and keep the filters; do not send after and before together. See Listing and pagination.
HTTP 202 keeps the result pending. It does not confirm payment and the SDK does not start polling. When resuming the saved order, load charge_id from storage and retrieve that same charge once:
with RaimsClient(api_key) as raims:
current = raims.charges.retrieve(charge_id)
print(f"HTTP status: {current.last_response.status_code}; charge status: {current.status}")HTTP 200 here confirms that the read succeeded. Interpret the returned status and payment_information using the charge reference; a successful GET does not mean the charge was paid or that issuance completed. If issuance is still pending, keep the same ID. Repeated reads do not speed up processing or issue another payment; contact support if the condition persists.
Idempotency and errors
Handle HTTP failures through ApiError, using status_code, code, and request_id. ConnectionError indicates a transport failure and can leave a write inconclusive. max_network_retries configures retries for reads only; the default is zero.
The SDK sends an idempotency key only when your application supplies it to an endpoint that accepts Idempotency-Key. It does not generate keys or retry writes automatically. A timeout does not prove that a write was rejected.
Make decisions using the HTTP status and structured code; error.message is a human diagnostic that can change. Do not log complete responses, credentials, personal documents, or temporary URLs. See Idempotency and the SDK error guide.
For example, if the read above returns HTTP 403 with API_KEY_PERMISSION_DENIED, the key lacks access to list customers. Enable View customers on the appropriate key and retry the read. Repeating it with the same permissions will not resolve that error.
For field validation failures, use error.details[].field and error.details[].code to locate the input to correct. Check HTTP response codes for other failures.
For an uncertain write, recover the saved key and the entire original payload. If the charge ID was received, retrieve that ID first. Within the idempotency retention period, a compatible retry can return the preserved result, including a pending 202. A key with different parameters can be rejected; do not change the due date or create a new key to bypass the uncertainty. After retention expires, reconcile before another write.
Use Sandbox
Use a Sandbox key for simulations in raims.simulations.charges and raims.simulations.refunds. A Production key does not become a Sandbox key when these services are used. Check the conditions in the Simulations reference.
Requests that ask for email or webhook deliveries can reach external destinations even in Sandbox. Use only destinations authorized for the integration.
Receive webhooks
raw_body contains the received bytes and received_headers contains webhook-id, webhook-timestamp, and webhook-signature. reject_delivery and persist_event represent your application logic. Do not process a delivery whose signature failed.
from raims import SignatureVerificationError, Webhook
try:
event = Webhook.construct_event(raw_body, received_headers, webhook_secret)
except SignatureVerificationError:
reject_delivery()
else:
persist_event(event)Use the secret_key returned when creating or rotating the webhook, which differs from the API Bearer key. Read the body before the JSON parser and preserve its bytes: do not reserialize the content before authentication.
After authentication, check the type and environment, deduplicate by the event id, and store the work durably before responding with success. The webhook-id header identifies the delivery, not the event. See Receive events.
Update the SDK
To install the current stable version, run in your application environment:
python -m pip install --upgrade raimsReview the release notes and test the flows used by your integration. Pin the version and dependencies in your application's dependency configuration to reproduce the installation. Future updates are not installed automatically.
If you installed from GitHub, the raims import stays the same. Update the
dependency source in your application configuration if it pins a Git URL or
local file. To keep using the downloaded wheel, download the files from the new
release, verify the hash, and install the new wheel with --upgrade.
The SDK version is independent of the API HTTP version /v1. Full guides and the method reference are in the SDK repository.