Python SDK for CodeSpar — commerce infrastructure for AI agents in Latin America.
Project description
codespar — Python SDK
Commerce infrastructure for AI agents in Latin America. Pix, NF-e, WhatsApp, shipping, banking — one API, no provider-key boilerplate.
Install
pip install codespar
Python 3.10+ required.
Quick start
from codespar import CodeSpar
cs = CodeSpar(api_key="csk_live_...")
session = cs.create(
"user_123",
preset="brazilian", # zoop, nuvem-fiscal, melhor-envio, z-api, omie
# project_id="prj_...", # optional — defaults to the org's default project
)
result = session.send(
"Charge R$500 via Pix to +5511999887766 and send the QR code by WhatsApp."
)
print(result.message)
for call in result.tool_calls:
print(f" → {call.tool_name} ({call.duration_ms}ms)")
session.close()
cs.close()
Or as a context manager:
with CodeSpar(api_key="csk_live_...") as cs:
session = cs.create("user_123", preset="brazilian")
print(session.send("Quero pagar R$125 via Pix").message)
Streaming
for event in session.send_stream("Process order #BR-7721"):
if event.type == "assistant_text":
print(event.content, end="", flush=True)
elif event.type == "tool_use":
print(f"\n→ calling {event.name}...")
elif event.type == "tool_result":
print(f" {event.tool_call.status} in {event.tool_call.duration_ms}ms")
Async
import asyncio
from codespar import AsyncCodeSpar
async def main():
async with AsyncCodeSpar(api_key="csk_live_...") as cs:
session = await cs.create("user_123", preset="brazilian")
result = await session.send("charge R$500 via Pix")
print(result.message)
await session.close()
asyncio.run(main())
Multi-environment (projects)
CodeSpar scopes every session to an environment (prj_<id>). Pass a
project id on the client for the whole lifetime, or per-session when
you want to target a different environment:
# Pin every session this client spawns to the staging project
cs = CodeSpar(api_key="csk_live_...", project_id="prj_staging0123abcd")
# Override per session
session = cs.create("user_123", preset="brazilian", project_id="prj_prod0123abcd")
When you omit project_id, CodeSpar routes to the org's default
project — always defined, self-healed on first read.
Raw HTTP proxy
Skip the agent loop and hit a provider API directly through CodeSpar's credential vault:
from codespar import ProxyRequest
response = session.proxy_execute(ProxyRequest(
server="stripe-acp",
endpoint="/v1/charges",
method="POST",
body={"amount": 2000, "currency": "brl"},
))
print(response.status, response.data)
No API key leaves your machine — CodeSpar injects it server-side.
Connect Links (OAuth)
from codespar import AuthConfig
link = session.authorize(
"stripe-acp",
AuthConfig(redirect_uri="https://your.app/connected"),
)
print(f"Open this URL to connect Stripe: {link.authorize_url}")
After the user completes the OAuth flow, CodeSpar stores the tokens in
the per-project vault and forwards them back to redirect_uri with
?status=connected&connection_id=<id> appended.
Errors
Every failure is wrapped:
from codespar import ApiError, ConfigError, StreamError
try:
session = cs.create("user_123", preset="brazilian")
except ConfigError as exc:
print(f"Bad config: {exc}")
except ApiError as exc:
print(f"Backend said {exc.status}: {exc.code}")
Design parity with the JS SDK
This package mirrors @codespar/sdk
method-for-method. Same backend, same payloads, same preset names — pick
the language that fits your stack without giving anything up.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codespar-0.1.0.tar.gz.
File metadata
- Download URL: codespar-0.1.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af32052bfda52ac4da3c468fda2f349d00cdc419e849e2d206f0915f40258fd6
|
|
| MD5 |
93fe2b3cdef43d706f59b3f2af09ecd3
|
|
| BLAKE2b-256 |
fa0b812f093ce60a244c3f87326c927ff05463e54276301566850fb5292f0e84
|
Provenance
The following attestation bundles were made for codespar-0.1.0.tar.gz:
Publisher:
publish-python.yml on codespar/codespar-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codespar-0.1.0.tar.gz -
Subject digest:
af32052bfda52ac4da3c468fda2f349d00cdc419e849e2d206f0915f40258fd6 - Sigstore transparency entry: 1352382463
- Sigstore integration time:
-
Permalink:
codespar/codespar-core@157b1287f9f4e0139a4be21ea9eaa5f9650bbb15 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/codespar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@157b1287f9f4e0139a4be21ea9eaa5f9650bbb15 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codespar-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codespar-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c964d5f972cf1c90416154ad5fdc922b91224d3921177e211859f650915acba
|
|
| MD5 |
6621eecdb391be89b5b50caa05b0751d
|
|
| BLAKE2b-256 |
418caadf8d426b3feb5580a06d7d4e56882ce5b53e68d0482e8c8f58c810e6dd
|
Provenance
The following attestation bundles were made for codespar-0.1.0-py3-none-any.whl:
Publisher:
publish-python.yml on codespar/codespar-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codespar-0.1.0-py3-none-any.whl -
Subject digest:
9c964d5f972cf1c90416154ad5fdc922b91224d3921177e211859f650915acba - Sigstore transparency entry: 1352382574
- Sigstore integration time:
-
Permalink:
codespar/codespar-core@157b1287f9f4e0139a4be21ea9eaa5f9650bbb15 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/codespar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@157b1287f9f4e0139a4be21ea9eaa5f9650bbb15 -
Trigger Event:
release
-
Statement type: