Skip to content

Configuration and errors

Where the SDK sends data, with which credentials, and for which project.

Configuration is scoped to an Opengrade instance (Settings, or OPENGRADE_* env vars at construction). Activate an instance for ambient helpers via current().

Settings dataclass

Settings(tracking_uri: str | None = None, api_key: str | None = None, project: str | None = None, project_id: str | None = None, project_slug: str | None = None, service_name: str | None = None, version: str | None = None, environment: str | None = None, live: bool | None = None, live_sample_rate: float | None = None, metrics_workers: int | None = None, max_capture_bytes: int | None = None, warned_plaintext_key: bool = False)

tracking_uri class-attribute instance-attribute

tracking_uri: str | None = None

api_key class-attribute instance-attribute

api_key: str | None = None

project class-attribute instance-attribute

project: str | None = None

project_id class-attribute instance-attribute

project_id: str | None = None

project_slug class-attribute instance-attribute

project_slug: str | None = None

service_name class-attribute instance-attribute

service_name: str | None = None

version class-attribute instance-attribute

version: str | None = None

environment class-attribute instance-attribute

environment: str | None = None

live class-attribute instance-attribute

live: bool | None = None

live_sample_rate class-attribute instance-attribute

live_sample_rate: float | None = None

metrics_workers class-attribute instance-attribute

metrics_workers: int | None = None

max_capture_bytes class-attribute instance-attribute

max_capture_bytes: int | None = None

warned_plaintext_key class-attribute instance-attribute

warned_plaintext_key: bool = False

from_env classmethod

from_env(**overrides: Any) -> Settings

Build settings from OPENGRADE_* env vars, then apply overrides.

with_updates

with_updates(**kwargs: Any) -> Settings

Opengrade

Opengrade(settings: Settings | None = None, **kwargs: Any)

Configurable opengrade runtime (settings, client, tracing, evaluate).

Opengrade(project="my-app") is enough: the rest comes from OPENGRADE_*.

project is a name, created on the platform if missing. project_id / project_slug point at an existing project instead. Any other Settings field can be passed as a keyword.

settings property

settings: Settings

client property

client: Client

async_client

async_client() -> AsyncClient

set_project

set_project(name: str) -> ProjectResponse | None

aset_project async

aset_project(name: str) -> ProjectResponse | None

get_project

get_project() -> ProjectResponse | None

configure_capture

configure_capture(*, max_capture_bytes: int | None | Any = _UNSET, redact: RedactFn | None | Any = _UNSET, redact_output: RedactOutputFn | None | Any = _UNSET) -> None

activate

activate() -> Iterator[Opengrade]

close

close() -> None

current

current() -> Opengrade

OpengradeError

Bases: Exception

Base error for opengrade SDK failures.

OpengradeAPIError

OpengradeAPIError(status: int, body: str, *, detail: Any = None)

Bases: OpengradeError

Raised when the platform API returns a non-2xx response.

status instance-attribute

status = status

body instance-attribute

body = body

detail instance-attribute

detail = detail

OpengradeConnectionError

OpengradeConnectionError(message: str, *, cause: BaseException | None = None)

Bases: OpengradeError

Raised when the platform cannot be reached (DNS, connect, timeout, …).