service
service
¶
REST API service for read-only database exposure via FastAPI.
Auto-generates paginated endpoints for all discovered tables, views, and materialized views. Per-table access control via TableConfig allows disabling individual endpoints.
The HTTP server runs as a background asyncio.Task alongside the
standard run_forever() cycle. Each run() cycle logs request
statistics and updates Prometheus metrics.
Note
Rate limiting is not enforced at the application level — it is expected to be handled by the reverse proxy (e.g., Cloudflare, Nginx). The API is strictly read-only: only GET methods are registered, and all queries are executed through the Catalog safe query builder.
See Also
ApiConfig: Configuration model for HTTP settings, pagination, and CORS. Catalog: Schema introspection and query builder shared with the DVM service. BaseService: Abstract base class providing lifecycle and metrics.
Examples:
from bigbrotr.core import Brotr
from bigbrotr.services import Api
brotr = Brotr.from_yaml("config/brotr.yaml")
api = Api.from_yaml("config/services/api.yaml", brotr=brotr)
async with brotr:
async with api:
await api.run_forever()
Classes¶
Api
¶
Bases: CatalogAccessMixin, BaseService[ApiConfig]
REST API service exposing the BigBrotr database read-only.
Auto-generates paginated GET endpoints for each enabled table, view, and materialized view discovered by the Catalog.
Lifecycle
__aenter__: discover schema, build FastAPI app, start uvicorn.run(): log statistics and update Prometheus gauges.__aexit__: cancel the HTTP server task.
See Also
ApiConfig: Configuration model for this service. Dvm: Sibling service that exposes the same Catalog data via Nostr NIP-90.
Source code in src/bigbrotr/services/api/service.py
Functions¶
cleanup
async
¶
run
async
¶
Log request stats and update Prometheus counters.
Detects a crashed HTTP server task and raises RuntimeError
to trigger the run_forever() failure counter. Per-cycle
request counters are snapshotted and reset atomically.