Skip to main content

Architecture

This document describes how sasvi is assembled, which parts are generated, and where handwritten behavior lives.

Design goals​

  • Preserve broad API coverage by generating service clients from source OpenAPI specs.
  • Keep the generated boundary explicit and replaceable.
  • Expose raw service-shaped operations in one consistent place: client.api.*.
  • Reserve top-level client namespaces for capability-first, handwritten feature modules.

High-level structure​

Repository layout​

openapi_definitions/ Spec lock (SOURCES.md); the specs are fetched, not committed
src/sasvi/_generated/ Generated clients, models, errors, and operation indices
src/sasvi/api/ Generated concrete raw facades and API namespace types
src/sasvi/__init__.py Package namespace; the public names load lazily
src/sasvi/__main__.py `python -m sasvi` runs the command line
src/sasvi/_client.py Top-level client composition and environment-based setup
src/sasvi/_runtime.py Retry-aware HTTPX clients, read budgets, redirect policy
src/sasvi/auth.py Token providers and HTTPX auth adapter
src/sasvi/config.py Shared runtime configuration (SVIConfig)
src/sasvi/settings.py The one SASVI_* settings resolver behind from_env() and the CLI
src/sasvi/profiles.py Named profiles in profiles.toml (sasvi profile, --profile)
src/sasvi/_token_store.py The sasvi auth login token cache
src/sasvi/redaction.py Public redaction helpers (redact_text, redact_headers)
src/sasvi/errors.py The typed error hierarchy (sasvi.errors)
src/sasvi/_errors_build.py Builders that turn a response into a typed error
src/sasvi/_compatibility.py What the release was built and verified against (sasvi.compatibility())
src/sasvi/_logging.py Redaction-aware HTTP logging
src/sasvi/_preview.py Request preview for handwritten methods (*_preview(), RequestPreview)
src/sasvi/_preview_runtime.py preview_next() and preview(): capture any handwritten call
src/sasvi/_document_runtime*.py Shared document runtime: locks, ETags, patches, refresh (core), files, sheets, children, metadata
src/sasvi/_document_write.py The locked document write, spelled out once
src/sasvi/_entity_metadata.py Entity-type metadata normalized into stable SDK shapes
src/sasvi/_filters.py SCIM-style filter expression helpers
src/sasvi/_admin_scope.py, _condition_records.py, _relationship_types.py, _job_handle.py
Records and handles shared by sasvi.admin and sasvi.documents
src/sasvi/_service_utils.py, _protocols.py, _typing.py, _fsutil.py, _deprecation.py
Binding helpers, structural protocols, type aliases, private-file writers, deprecation
src/sasvi/handles.py Public handle base class for raw-payload wrappers
src/sasvi/values.py Chooser value types (UserRef, GroupRef)
src/sasvi/custom.py client.custom: origin-locked raw requests to extension endpoints
src/sasvi/types/ Literal aliases for closed-set strings + generated wire types and models by service
src/sasvi/documents/ Bound document objects and nested document-owned managers
src/sasvi/alerts/ Specialized alert objects built on top of documents + Alerts APIs
src/sasvi/admin/ Configuration/admin services exposed as client.admin
src/sasvi/reference_lists/ Reference-list capability module (exposed as client.admin.reference_lists)
src/sasvi/search/ Search capability module and hydration-friendly result refs
src/sasvi/workflows/ Bound workflow tasks/processes/definitions
src/sasvi/entities/ Handwritten entity metadata and typed payload helpers
src/sasvi/insights/ Insight payload models reused by the document layer
src/sasvi/cli/ The sasvi command line (the optional `cli` extra)
tools/generate_sdk/ Normalization, code generation, and patch pipeline
tools/spec_diff.py OpenAPI spec comparison report for version updates
tools/verify.py Project-wide verification entry point
tests/ Runtime, generation, normalization, and smoke tests

Runtime composition​

SVIClient in src/sasvi/_client.py is the package entry point.

At construction time it:

  1. builds an SVIConfig
  2. binds the configured token provider to the base URL when the provider needs it
  3. builds one sync and one async connection pool for the whole client (build_shared_pool in src/sasvi/_runtime.py)
  4. iterates through the service registry in SERVICE_DEFINITIONS
  5. imports the generated client class for each service
  6. creates retry-aware sync and async HTTPX clients on the shared pools and installs them into the generated client instance
  7. instantiates the generated concrete raw facade for each service
  8. assembles client.api from those concrete facades
  9. creates the shared capability and object layer from the raw API namespaces

Request lifecycle​

For a typical raw call such as client.api.workflows.get_workflows():

  1. SVIClient exposes the prebuilt client.api.workflows namespace
  2. the concrete WorkflowsAPI facade method calls the generated operation module
  3. the generated function executes using the configured generated client
  4. the generated client uses the installed HTTPX sync or async client
  5. BearerTokenAuth obtains a token from the configured provider
  6. the retrying HTTPX client applies transport retry rules
  7. the caller receives the parsed response model

Handwritten capability modules compose on top of the raw client.api layer rather than bypassing it.

Generated code boundary​

Everything under src/sasvi/_generated is generated output. Treat it as a replaceable build artifact, even though it is committed to the repository.

Generated content includes:

  • service client classes
  • request and response models
  • generated error models
  • raw operation modules under api/
  • _operation_index.py

Do not hand-edit generated files.

Handwritten code boundary​

Handwritten code exists for concerns that are not stable or ergonomic to express in the OpenAPI generator alone:

  • top-level package exports
  • common configuration and service routing
  • auth provider implementations
  • retry policy
  • environment-driven client construction
  • generated raw facade binding under client.api, which also translates the generated layer's exceptions into sasvi.errors
  • shared document runtime for locks, ETags, patches, and refresh
  • stable model and type re-export modules
  • capability modules and bound objects

The handwritten layer splits into:

  • generic infrastructure: src/sasvi/api, src/sasvi/_client.py, src/sasvi/_runtime.py
  • capability and object layer: src/sasvi/documents, src/sasvi/alerts, src/sasvi/admin, src/sasvi/reference_lists, src/sasvi/search, src/sasvi/workflows, src/sasvi/entities

Raw service facades are generated artifacts. Do not hand-edit them.

Service routing​

Each service has:

  • a generated client module
  • an operation index module
  • a default relative base path

Those are declared in SERVICE_DEFINITIONS in src/sasvi/_client.py.

Default paths are:

  • Alerts: /svi-alert
  • Data Hub: /svi-datahub
  • Files: /files
  • Folders: /folders
  • Search and Discovery: /svi-sand
  • Transport: /svi-transport
  • Workflows: /svi-datahub/workflows

SVIConfig.service_url() resolves each final service URL from either:

  • service_urls[service_name]
  • base_url + default_path

Authentication model​

The SDK ships four token providers:

  • StaticTokenProvider
  • ClientCredentialsTokenProvider
  • UsernamePasswordTokenProvider
  • AuthorizationCodeTokenProvider

All providers implement the same sync and async token protocol consumed by BearerTokenAuth.

Retry model​

Custom subclasses of httpx2.Client and httpx2.AsyncClient in src/sasvi/_runtime.py implement the retries.

The retry policy is intentionally narrow by default:

  • methods: DELETE, GET, HEAD, OPTIONS, PUT
  • statuses: 408, 429, 500, 502, 503, 504
  • transport errors are retried only for configured retryable methods
  • backoff uses exponential growth from RetryPolicy.backoff_seconds, with jitter

POST and PATCH are excluded by default to avoid reissuing non-idempotent requests without an explicit decision from the caller.

Operation binding​

The generator emits one concrete facade class per public raw service. Each facade defines explicit methods for the generated operation modules and preserves the <operation>, <operation>_detailed, <operation>_async, and <operation>_detailed_async naming pattern used by openapi-python-client.

Public stability model​

The package exposes three stability tiers:

  1. stable SDK entry points: SVIClient, SVIConfig, auth providers, client.api, and the top-level capability modules
  2. broad but generated surface: bound raw operations and generated models and types
  3. internal implementation details: normalization and runtime wiring internals