Core Concepts
Understand the key building blocks of the nekuda Python SDK.
Before jumping into advanced usage, it’s worth getting familiar with the building blocks that form the nekuda SDK public surface.
NekudaClient
The single entry-point to all network operations that:
- Manages an internal persistent
httpx.Client
with automatic retry & back-off for 5xx / 429 responses - Can be instantiated directly or via the convenience constructor
NekudaClient.from_env()
- Automatically normalizes URLs (adds
https://
, removes trailing slashes). The defaultbase_url
ishttps://api.nekuda.ai
.
UserContext
A lightweight wrapper returned by client.user(user_id)
that automatically injects the user_id
header on every call.
A user_id
is mandatory for all user-specific operations like creating mandates or revealing cards.
Behind the scenes no extra network round-trip happens for
client.user(user_id)
– UserContext
is just a convenience object that
stores the user_id
.
MandateData
A small dataclass that represents the user’s intent to purchase.
It must be successfully submitted via user.create_mandate(mandate_data)
to obtain a mandate_id
before you can request a card reveal token.
Client-side validation runs in __post_init__
. Invalid payloads raise NekudaValidationError
before any HTTP request is made.
Response Models 🎯
All API methods now return typed Pydantic models instead of raw dictionaries. This provides:
- Type safety - Your IDE knows exactly what fields are available
- Validation - Card numbers, expiry dates, etc. are automatically validated
- Better errors - Clear messages when API returns unexpected data
Key Response Models
Example with Type Safety
Error Hierarchy
All exceptions inherit from a common NekudaError
base class so a single except block can catch everything:
NEW: The SDK now detects and properly handles HTML error pages (nginx errors, gateway timeouts) that sometimes occur during infrastructure issues.
For a deep-dive see the dedicated Error Handling page.
Advanced Features 🚀
Response Validation
The SDK automatically validates all API responses:
URL Normalization
The default base_url
is https://api.nekuda.ai
. You generally don’t need to set this unless using a staging or mock server.
Thread-safety & Re-usability
NekudaClient
is designed to be cheap to instantiate but you can (and should) reuse a single instance across the lifetime of your process for maximum performance. Internally it lazily creates the underlying HTTP session the first time you make a request.
Future Roadmap
Async Support Coming Soon 🔮 The public API has been designed with parity
in mind, so an AsyncNekudaClient
will drop in without breaking changes.