This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
sbxpy is a Python SDK for the SBXCloud BaaS (Backend as a Service) platform. It provides async HTTP clients (via aiohttp) for CRUD operations, querying, event handling, workflow management, and optional Redis caching. Published to PyPI as sbxpy.
- Package manager: uv
- Python: >= 3.12 (pyproject.toml) / >= 3.13 (README target)
- Install dependencies:
uv sync - Add dependency:
uv add <package> - Run a script:
uv run <script.py> - Build package:
python setup.py sdist bdist_wheel - No test suite exists β test manually via scripts with env vars configured
Required for SBXCloud connection:
SBX_DOMAINβ domain IDSBX_APP_KEYβ application keySBX_TOKENβ auth tokenSBX_HOSTβ base URL (e.g.,https://sbxcloud.com/api)
Optional for Redis caching:
REDIS_HOST,REDIS_PORT,REDIS_USER,REDIS_PASSWORD
All library code lives in sbxpy/. The build/ directory contains stale build artifacts.
Contains multiple client classes, each following the same pattern: initialize with domain/credentials, build queries, execute async HTTP requests via aiohttp.
SbxCoreβ Main SBXCloud client. Handles auth, CRUD (upsert,login), cloudscript management (run,create_cloudscript,list_cloudscripts,get_cloudscript,update_cloudscript), model/field management (create_model,create_field,list_domain), and createsFindquery objects viawith_model().Findβ Fluent query builder for find/delete operations. Supportsand_where_*/or_where_*conditions,fetch_models(JOINs), pagination,find_all()with concurrent page fetching via semaphore-limitedasyncio.gather.SbxEvent/EventQueryβ Client for the SBXCloud event service (separate base URL, usessbx-secretheader).SbxWorkflow/WorkflowQueryβ Client for workflow/process execution API.SbxCRMUser/UserQueryβ Client for CRM user management API.ReferenceJoin/FilterJoinβ Reference join query helpers.
Low-level query JSON builder. Constructs the where, rows, fetch, order_by, and page/size parameters sent to the SBXCloud API.
SBXModelβ Pydantic BaseModel base class for all domain models. Maps_KEYtokeyfield. Hashable by key.@sbx(model="name")β Decorator that binds a model class to an SBXCloud model name (stored ascls._model).MetaModelβ Timestamps sub-model (created_time,updated_time).
SBXβ Singleton accessor forSbxCore, reads credentials from env vars.SBXServiceβ Abstract base withfind(),get_by_key(),list_all()convenience methods.SBXResponseβ Pydantic model wrapping API responses. Key methods:all(Type),first(Type),get_ref(model, key, Type),merge(),has_results().
RedisServiceβ Async Redis client (viaredis.asyncio) for caching Pydantic objects as JSON. Supports get/set/mget/mset with optional TTL, plus key index management.
SBXCachedServiceβ ExtendsSBXServicewith Redis cache-through pattern forget()andlist()operations.
POST /data/v1/rowβ insert recordsPOST /data/v1/row/updateβ update recordsPOST /data/v1/row/findβ query recordsPOST /data/v1/row/deleteβ delete records
GET /data/v1/row/model/list?domain={id}β list models (list_domain())POST /data/v1/row/model?domain={id}&name={name}β create model (create_model())POST /data/v1/field/model?domain={id}&name={name}&row_model_id={id}&type={type}β create field (create_field()). Field types:STRING,INT,FLOAT,BOOLEAN,TEXT,REFERENCE. ForREFERENCE, passreference_type=target_model_id.
POST /cloudscript/v1/runβ execute a cloudscript (run())POST /cloudscript/v1.5/{domain_id}β create cloudscript (create_cloudscript())GET /cloudscript/v1.5/{domain_id}?page=Nβ list cloudscripts (list_cloudscripts())GET /cloudscript/v1.5/{domain_id}/{key}β get cloudscript (get_cloudscript())PUT /cloudscript/v1.5/{domain_id}/{key}/scriptβ update cloudscript (update_cloudscript())
- All API calls are async (use
await). The library usesaiohttp.ClientSessionper request. upsert()separates items with_KEY(updates) from those without (inserts) and sends them to different endpoints (/data/v1/row/updatevs/data/v1/row).- Maximum 1000 records per upsert call.
find_all()fetches the first page, readstotal_pages, then fetches remaining pages concurrently with semaphore-limited parallelism (default 2).- Dates in SBXCloud are often stored as
intinYYYYMMDDformat. - Domain models use Pydantic v2 with
populate_by_name=Trueto handle the_KEYalias.