Python
The codespar package on PyPI: which Session methods exist under their snake_case names, and what the TypeScript SDK has that Python does not.
Python
codespar 0.11.0 on PyPI; 0.11.0 on the main branch of codespar-core.
pip install codesparTwo clients over the same backend: CodeSpar is synchronous (scripts, notebooks, Flask and Django views) and AsyncCodeSpar is asyncio (FastAPI, LangChain, anything already on an event loop). Both return a session with the same method names; the async one returns coroutines.
from codespar import CodeSpar
cs = CodeSpar(api_key="csk_test_0000")
session = cs.create("user_0000", preset="brazilian")
try:
result = session.send("Charge R$150 via Pix and issue the NF-e")
print(result.message)
finally:
session.close()
cs.close()from codespar import AsyncCodeSpar
async with AsyncCodeSpar(api_key="csk_test_0000") as cs:
session = await cs.create("user_0000", preset="brazilian")
async for event in session.send_stream("Charge R$150 via Pix"):
if event.type == "assistant_text":
print(event.content, end="")
await session.close()Three things differ from the TypeScript package on purpose, and the tables below say which names exist on each side:
- Names are snake_case.
paymentStatusStreamispayment_status_stream;findToolsisfind_tools. A TypeScript page that mentions a Python name labels it as such. - Timeouts are in seconds, following
httpx.timeout=30is thirty seconds here and thirty milliseconds in TypeScript; do not copy a number between the two. - Errors are a hierarchy under
CodeSparError.ApiErrorcarriesstatus,codeandbodylikeCodesparApiErrordoes;ConfigError,NotConnectedErrorandStreamErrorhave no TypeScript counterpart.
Streams accept on_update= (sync or async callable) and timeout=; the promise-style signal of the TypeScript SDK has no equivalent, cancel the task instead. The Python stream relies on the httpx read timeout, which any incoming byte resets; the TypeScript one resets only on a complete SSE frame. Both are documented liveness models and are deliberately not unified.
The codespar.mandate module (verify_mandate_token, decode_mandate_token) matches the @codespar/sdk/mandate subpath: offline V3 mandate verification with no API call.
Session methods
One row per method of the TypeScript Session. The Python column is the signature as written in _sync_client.py; AsyncSession has the same names as coroutines.
| TypeScript | Python (Session) | AsyncSession |
|---|---|---|
tools | tools(self) -> list[Tool]: | async tools |
findTools | find_tools(self, intent: str) -> list[Tool]: | async find_tools |
execute | `execute(self, tool_name: str, params: dict[str, Any], *, timeout: float | None = None) -> ToolResult:` |
proxyExecute | `proxy_execute(self, request: ProxyRequest, *, timeout: float | None = None) -> ProxyResult:` |
send | `send(self, message: str, *, timeout: float | None = None) -> SendResult:` |
sendStream | `send_stream(self, message: str, *, timeout: float | None = None) -> Iterator[StreamEvent]:` |
discover | `discover(self, use_case: str, options: DiscoverOptions | None = None, *, timeout: float |
connectionWizard | `connection_wizard(self, options: ConnectionWizardOptions, *, timeout: float | None = None) -> ConnectionWizardResult:` |
charge | `charge(self, args: ChargeArgs, *, timeout: float | None = None) -> ChargeResult:` |
ship | `ship(self, args: ShipArgs, *, timeout: float | None = None) -> ShipResult:` |
ledger | `ledger(self, args: LedgerArgs, *, timeout: float | None = None) -> LedgerResult:` |
issue | `issue(self, args: IssueArgs, *, timeout: float | None = None) -> IssueResult:` |
shop | `shop(self, args: ShopArgs, *, timeout: float | None = None) -> ShopResult:` |
paymentStatus | `payment_status(self, tool_call_id: str, *, timeout: float | None = None) -> PaymentStatusResult:` |
verificationStatus | `verification_status(self, tool_call_id: str, *, timeout: float | None = None) -> VerificationStatusResult:` |
paymentStatusStream | `payment_status_stream(self, tool_call_id: str, *, on_update: Any | None = None, timeout: float |
verificationStatusStream | `verification_status_stream(self, tool_call_id: str, *, on_update: Any | None = None, timeout: float |
authorize | `authorize(self, server_id: str, config: AuthConfig, *, timeout: float | None = None) -> AuthResult:` |
connections | `connections(self, *, timeout: float | None = None) -> list[ServerConnection]:` |
close | `close(self, *, timeout: float | None = None) -> None:` |
Client, functions and errors
| TypeScript | Python |
|---|---|
new CodeSpar(config) | CodeSpar(api_key=..., base_url=..., project_id=..., timeout=...) and AsyncCodeSpar(...) |
create | `create(self, user_id: str, config: SessionConfig |
cs.api | not in Python: there is no generated REST client; call api.codespar.dev with httpx directly |
SessionConfigSchema | not in Python |
loop | not in Python |
tools | session.tools() (a method, not a free function) |
findTools | session.find_tools() (a method, not a free function) |
CodesparApiError | ApiError |
TimeoutError | TimeoutError |
TOOL_RESULT_CODES | TOOL_RESULT_CODES |
ToolResultCode | ToolResultCode |
assertExhaustiveToolResult | assert_exhaustive_tool_result |
isApprovalRequired | is_approval_required |
isMocksEngineError | is_mocks_engine_error |
isMocksExhausted | is_mocks_exhausted |
isPolicyDenied | is_policy_denied |
isToolNotMocked | is_tool_not_mocked |
ApiClient | not in Python |
createApiClient | not in Python |
API_OPERATIONS | not in Python |
Only in Python
CodeSparError(Exception)ConfigError(CodeSparError)NotConnectedError(CodeSparError)StreamError(CodeSparError)session.info(property)await AsyncCodeSpar.aclose()(andCodeSpar.close()): the client owns the HTTP transport and must be closed