Skip to main content

FastAPI integration for the Bella Baxter secret management SDK

Project description

bella-baxter-fastapi

FastAPI integration for the Bella Baxter secrets management platform. Provides a BellaDepends dependency annotation for injecting a BaxterClient into route handlers.

Installation

pip install bella-baxter-fastapi

Quickstart

from contextlib import asynccontextmanager
from fastapi import FastAPI
from bella_baxter_fastapi import init_bella, BellaDepends

@asynccontextmanager
async def lifespan(app: FastAPI):
    init_bella(api_key="bax-...")
    yield

app = FastAPI(lifespan=lifespan)

@app.get("/health")
async def health(bella: BellaDepends):
    secrets = await bella.get_all_secrets_async()
    return {"database": secrets.secrets.get("DATABASE_URL")}

init_bella()

Call once at startup (inside a lifespan handler or module level) to initialise the shared client:

from bella_baxter_fastapi import init_bella

init_bella(
    api_key="bax-...",
    baxter_url="https://api.bella-baxter.io",  # optional
)

BellaDepends

A typed Annotated dependency that injects the shared BaxterClient:

from bella_baxter_fastapi import BellaDepends

@app.get("/secrets")
async def get_secrets(bella: BellaDepends):
    resp = await bella.get_all_secrets_async()
    return resp.secrets

Configuration via environment variables

import os
from bella_baxter_fastapi import init_bella

init_bella(
    api_key=os.environ["BELLA_BAXTER_API_KEY"],
    baxter_url=os.environ.get("BELLA_BAXTER_URL", "https://api.bella-baxter.io"),
)

Authentication

Generate an API key via the CLI or the Bella WebApp:

bella api-keys create --env production --name "FastAPI Production"

Using secrets at startup (before first request)

@asynccontextmanager
async def lifespan(app: FastAPI):
    init_bella(api_key=os.environ["BELLA_BAXTER_API_KEY"])

    # Pre-fetch secrets to warm the cache
    from bella_baxter_fastapi import _get_bella_client
    client = _get_bella_client()
    secrets = await client.get_all_secrets_async()
    app.state.db_url = secrets.secrets["DATABASE_URL"]
    yield

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bella_baxter_fastapi-0.1.1rc42.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bella_baxter_fastapi-0.1.1rc42-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file bella_baxter_fastapi-0.1.1rc42.tar.gz.

File metadata

  • Download URL: bella_baxter_fastapi-0.1.1rc42.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bella_baxter_fastapi-0.1.1rc42.tar.gz
Algorithm Hash digest
SHA256 ecd4ebcb4b2cdd74817847a3530b9595490006974dc0e14b94b27d9d75e1abaa
MD5 696af552d2356df3fc0e6e063fd4e20c
BLAKE2b-256 7c0f9288dc899460cc68247f599ce06c452802f4515d7f9ea6247fa60bfaaf01

See more details on using hashes here.

Provenance

The following attestation bundles were made for bella_baxter_fastapi-0.1.1rc42.tar.gz:

Publisher: publish.yml on Cosmic-Chimps/bella-baxter-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bella_baxter_fastapi-0.1.1rc42-py3-none-any.whl.

File metadata

File hashes

Hashes for bella_baxter_fastapi-0.1.1rc42-py3-none-any.whl
Algorithm Hash digest
SHA256 307679a1fed9f0e8be2791e1630a6eecfba345cb490e58f54da20f18f13d637a
MD5 ba11989b3067af585a05317026a7a724
BLAKE2b-256 ba6aa7fc83e1ab8c4e9cd1e7f1730bdda20ccfe98a761628839a30b853bf8efc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bella_baxter_fastapi-0.1.1rc42-py3-none-any.whl:

Publisher: publish.yml on Cosmic-Chimps/bella-baxter-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page