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)
Tool discovery + connection wizard
Beyond session.execute(tool, params), the SDK exposes typed wrappers
for the F3.M2 meta-tools codespar_discover and
codespar_manage_connections:
from codespar import CodeSpar, ConnectionWizardOptions, DiscoverOptions
with CodeSpar(api_key="csk_live_...") as cs:
session = cs.create("user_123", preset="brazilian")
# Find the right tool for a free-form use case.
found = session.discover(
"send a pix payment",
DiscoverOptions(country="BR", limit=3),
)
if found.recommended:
print(found.recommended.server_id, found.recommended.tool_name)
print(f" status: {found.recommended.connection_status}")
# Surface the connection wizard if the recommended server isn't
# connected. NEVER pass credentials through this method —
# credentials only travel via the dashboard's connect modal or
# the OAuth callback. The wizard returns a deep-link the agent
# surfaces so the user finishes setup in their browser.
if found.recommended and found.recommended.connection_status == "disconnected":
wiz = session.connection_wizard(
ConnectionWizardOptions(
action="initiate",
server_id=found.recommended.server_id,
),
)
if wiz.initiate:
print("Connect:", wiz.initiate.connect_url)
for line in wiz.initiate.instructions:
print(" ·", line)
Async users have the same surface on AsyncSession
(await session.discover(...), await session.connection_wizard(...)).
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.
Need more?
Need governance, budget limits, and audit trails for agent payments? CodeSpar Enterprise adds policy engine, payment routing, and compliance templates on top of these MCP servers.
Links
Project details
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.9.0.tar.gz.
File metadata
- Download URL: codespar-0.9.0.tar.gz
- Upload date:
- Size: 29.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a63afee3158d2aa91e60f463a019ad657f6cf7df5c732c8c3100e9d975809002
|
|
| MD5 |
78586020a5be469bc38f805bfbeb8c86
|
|
| BLAKE2b-256 |
ff0afeca357f9e0da7e9ec911ac6353b00b17e4607c327c411ac314cfcefc19f
|
Provenance
The following attestation bundles were made for codespar-0.9.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.9.0.tar.gz -
Subject digest:
a63afee3158d2aa91e60f463a019ad657f6cf7df5c732c8c3100e9d975809002 - Sigstore transparency entry: 1437841548
- Sigstore integration time:
-
Permalink:
codespar/codespar-core@c421a0b2352d2c5495fc622cff15fd7f6cf1cfc9 -
Branch / Tag:
refs/tags/python-v0.9.0 - Owner: https://github.com/codespar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c421a0b2352d2c5495fc622cff15fd7f6cf1cfc9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codespar-0.9.0-py3-none-any.whl.
File metadata
- Download URL: codespar-0.9.0-py3-none-any.whl
- Upload date:
- Size: 26.2 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 |
31c517cecb9a9d10229786f4bcee5b08a04515454ca9e3e85c9030fe616b0257
|
|
| MD5 |
4e291dd926ac91d9998674a5238d1603
|
|
| BLAKE2b-256 |
d1e07f53cb3fb2d44f4361ad2b05ad4ec5e8b4b8b1c96935174fb890edaba9d4
|
Provenance
The following attestation bundles were made for codespar-0.9.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.9.0-py3-none-any.whl -
Subject digest:
31c517cecb9a9d10229786f4bcee5b08a04515454ca9e3e85c9030fe616b0257 - Sigstore transparency entry: 1437841566
- Sigstore integration time:
-
Permalink:
codespar/codespar-core@c421a0b2352d2c5495fc622cff15fd7f6cf1cfc9 -
Branch / Tag:
refs/tags/python-v0.9.0 - Owner: https://github.com/codespar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c421a0b2352d2c5495fc622cff15fd7f6cf1cfc9 -
Trigger Event:
release
-
Statement type: