Docs

Python SDK

Install sovaria-sdk, create an async or sync client, handle errors, set scope — and find every method by area.

Updated Nov 25, 2026

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,
) -> SovariaClient

Inside 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 | Noneoptionaldefault None
keystr | Noneoptionaldefault None

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,
) -> SovariaSyncClient

Parameters

configSovariaPortalConfig | dict[str, Any] | str | Noneoptionaldefault None
keystr | Noneoptionaldefault None

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,
) -> SovariaClient

Parameters

config_pathstr | pathlib.Path | Noneoptionaldefault None
access_tokenstr | Noneoptionaldefault None

Returns

SovariaClient

sovaria.aclose

Close the HTTP connection pool (also done by leaving async with).

await sovaria.aclose() -> None

Returns

None

sovaria.clear_context

Deprecated alias for :meth:clear_scope.

sovaria.clear_context() -> SovariaClient

Returns

SovariaClient

sovaria.clear_scope

Clear default org/project/env scope headers.

sovaria.clear_scope() -> SovariaClient

Returns

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) -> RestTable

See :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,
) -> SovariaClient

Parameters

envdict[str, str] | Noneoptionaldefault None
timeoutfloatoptionaldefault 30.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,
) -> SovariaClient

Pre-populates scope headers and access token so the returned client is ready to make scope-bound calls.

Parameters

configSovariaPortalConfig | dict[str, Any]required
timeoutfloatoptionaldefault 30.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,
) -> Any

Parameters

methodstrrequired
HTTP method.
pathstrrequired
API path, e.g. /api/v1/sql/query.
jsondict[str, Any] | list[Any] | Noneoptionaldefault None
JSON body.
paramsdict[str, str] | Noneoptionaldefault None
Query string.
requires_authbooloptionaldefault True
Send the session or key.
headersdict[str, str] | Noneoptionaldefault None
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] | None

Returns

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) -> Any

Parameters

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,
) -> SovariaClient

Parameters

access_tokenstrrequired
expires_inintoptionaldefault 31536000

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,
) -> SovariaClient

Parameters

org_idstrrequired
project_idstrrequired
env_idstr | Noneoptionaldefault None

Returns

SovariaClient

sovaria.set_org_plan

Set org plan.

await sovaria.set_org_plan(org_id: str, plan: str) -> dict[str, Any]

Parameters

org_idstrrequired
planstrrequired

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,
) -> SovariaClient

Parameters

org_idstrrequired
Organization id.
project_idstrrequired
Project id.
env_idstr | Noneoptionaldefault None
An environment (e.g. staging) instead of production.

Returns

SovariaClient

#Reference by area