Python SDK
Install sovaria-sdk, create an async or sync client, handle errors, set scope — and find every method by area.
sovaria-sdk 0.15.0 is the official Python client for Sovaria. SovariaClient is async (await; create_client(project_url, anon_key) needs no async with and finds the project from the URL; aclose() closes it); create_sync_client() returns the same methods for scripts and notebooks that don't use asyncio. It keeps the user's session, sends your project's scope with every call and retries safely.
#Install
pip install sovaria-sdk#Create a client
from sovaria import create_client
sovaria = create_client("https://<project-ref>.sovarias.in", "<anon-key>")
rows = await sovaria.from_("books").select("id,title").order("title", desc=True)
await sovaria.aclose() # when the program ends (or use `async with create_client(...) as sovaria:`)In a browser-less server, keep the service role key in a secret store and never send it to clients; for per-user work, sign the user in with their own credentials instead.
#Errors
Failed calls raise SovariaError with status_code and detail (the server's message or body). Plan limits come back as 403 with a detail containing code (PLAN_LIMIT_REACHED, PLAN_FEATURE_REQUIRED, PLAN_QUOTA_EXHAUSTED) — see Troubleshooting.
from sovaria import SovariaError
try:
await sovaria.sql_query("select * from orders")
except SovariaError as err:
if err.status_code == 401:
... # sign in again
elif err.status_code == 429:
... # back off
else:
raise#Client, scope and raw requests
create_client
Create a client — create_client("https://<ref>.sovarias.in", "<anon-key>") with the two values from the console's Connect panel, or a portal-style config dict.
With no arguments it reads the environment: SOVARIA_URL plus SOVARIA_SERVICE_ROLE_KEY, the function's own SOVARIA_FUNCTION_KEY or SOVARIA_ANON_KEY.
create_client(
config: SovariaPortalConfig | dict[str, Any] | str | None = None,
key: str | None = None,
) -> SovariaClientInside a Sovaria function every call has the URL and its own short-lived key, so create_client() is all it takes.
Parameters
configSovariaPortalConfig | dict[str, Any] | str | NoneoptionaldefaultNonekeystr | NoneoptionaldefaultNone
Returns
SovariaClient
create_sync_client
Synchronous variant of :func:create_client (no arguments: from the environment).
create_sync_client(
config: SovariaPortalConfig | dict[str, Any] | str | None = None,
key: str | None = None,
) -> SovariaSyncClientParameters
configSovariaPortalConfig | dict[str, Any] | str | NoneoptionaldefaultNonekeystr | NoneoptionaldefaultNone
Returns
SovariaSyncClient
client_from_config_file
Create a client from sovaria.config.json (walks up from cwd when path omitted).
client_from_config_file(
config_path: str | pathlib.Path | None = None,
*, access_token: str | None = None,
) -> SovariaClientParameters
config_pathstr | pathlib.Path | NoneoptionaldefaultNoneaccess_tokenstr | NoneoptionaldefaultNone
Returns
SovariaClient
sovaria.aclose
Close the HTTP connection pool (also done by leaving async with).
await sovaria.aclose() -> NoneReturns
None
sovaria.clear_context
Deprecated alias for :meth:clear_scope.
sovaria.clear_context() -> SovariaClientReturns
SovariaClient
sovaria.clear_scope
Clear default org/project/env scope headers.
sovaria.clear_scope() -> SovariaClientReturns
SovariaClient
sovaria.from_
One table of the project's database through the REST API (/rest/v1): the way apps read and write rows.
await sov.from_("books").select("id,title").eq("genre", "sci-fi").order("title") → rows; await sov.from_("clubs").insert({"name": n}) → the stored row (id and owner column filled in); .update(values).eq("id", id), .delete().eq("id", id), .upsert(...), .count().
sovaria.from_(table: str) -> RestTableSee :mod:sovaria.table_query.
Parameters
tablestrrequired
Returns
RestTable
sovaria.from_env
Build a client from environment variables (raises if URL absent).
Reads SOVARIA_URL (or NEXT_PUBLIC_SOVARIA_URL / VITE_SOVARIA_URL) plus optional SOVARIA_ORG_ID / SOVARIA_PROJECT_ID / SOVARIA_ENV_ID / SOVARIA_PUBLISHABLE_KEY (or SOVARIA_ACCESS_TOKEN / SOVARIA_ANON_KEY).
sovaria.from_env(
env: dict[str, str] | None = None,
*, timeout: float = 30.0,
) -> SovariaClientParameters
envdict[str, str] | NoneoptionaldefaultNonetimeoutfloatoptionaldefault30.0
Returns
SovariaClient
sovaria.from_portal_config
Build a client from portal-style configuration.
Accepts a SovariaPortalConfig or a raw dict (which is normalised via SovariaPortalConfig.from_dict).
sovaria.from_portal_config(
config: SovariaPortalConfig | dict[str, Any],
*, timeout: float = 30.0,
) -> SovariaClientPre-populates scope headers and access token so the returned client is ready to make scope-bound calls.
Parameters
configSovariaPortalConfig | dict[str, Any]requiredtimeoutfloatoptionaldefault30.0
Returns
SovariaClient
sovaria.request
Execute a raw gateway request. This is intentionally public so applications can use new gateway endpoints immediately even before a typed wrapper lands in the SDK.
await sovaria.request(
method: str,
path: str,
*, json: dict[str, Any] | list[Any] | None = None,
params: dict[str, str] | None = None,
requires_auth: bool = True,
headers: dict[str, str] | None = None,
) -> AnyParameters
methodstrrequired- HTTP method.
pathstrrequired- API path, e.g.
/api/v1/sql/query. jsondict[str, Any] | list[Any] | NoneoptionaldefaultNone- JSON body.
paramsdict[str, str] | NoneoptionaldefaultNone- Query string.
requires_authbooloptionaldefaultTrue- Send the session or key.
headersdict[str, str] | NoneoptionaldefaultNone- Extra headers.
Returns
Any
- For endpoints the typed methods don't cover; retries, auth and scope work the same.
sovaria.resolve_scope
Org/project this client talks to: set with set_scope(), or discovered once from the project URL (https://<ref>.sovarias.in), so create_client(project_url, anon_key) is enough.
await sovaria.resolve_scope() -> tuple[str, str] | NoneReturns
tuple[str, str] | None
sovaria.run_sync
Deprecated: prefer :class:SovariaSyncClient for synchronous callers.
Raises if an event loop is already running (notebooks / nested async).
sovaria.run_sync(coro: Any) -> AnyParameters
coroAnyrequired
Returns
Any
sovaria.set_access_token
Inject a pre-issued bearer token (portal publishable/anon key style).
sovaria.set_access_token(
access_token: str,
*, expires_in: int = 31536000,
) -> SovariaClientParameters
access_tokenstrrequiredexpires_inintoptionaldefault31536000
Returns
SovariaClient
sovaria.set_context
Deprecated alias for :meth:set_scope.
Raises if :meth:set_scope was already called with a different org/project.
sovaria.set_context(
org_id: str,
project_id: str,
env_id: str | None = None,
) -> SovariaClientParameters
org_idstrrequiredproject_idstrrequiredenv_idstr | NoneoptionaldefaultNone
Returns
SovariaClient
sovaria.set_org_plan
Set org plan.
await sovaria.set_org_plan(org_id: str, plan: str) -> dict[str, Any]Parameters
org_idstrrequiredplanstrrequired
Returns
dict[str, Any]
{
"org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"plan": "free"
}sovaria.set_scope
Set default org/project/env scope headers for subsequent requests.
sovaria.set_scope(
org_id: str,
project_id: str,
env_id: str | None = None,
) -> SovariaClientParameters
org_idstrrequired- Organization id.
project_idstrrequired- Project id.
env_idstr | NoneoptionaldefaultNone- An environment (e.g. staging) instead of production.
Returns
SovariaClient