# Python SDK

A first-party `envshed` package for Python — fetch secrets from your Django, FastAPI, or script entry points without shelling out to the CLI.

:::note Planned
The Python SDK is planned with sync and async clients, typed responses, and a `load_dotenv()`-style helper. Until then, Python projects get the same behavior through the [CLI](../cli/overview) or the REST API.
:::

## How it will work

- **One install** — `pip install envshed` (or `uv add envshed`) gives you a typed client and a `load_env()` helper.
- **Drop-in for `python-dotenv`** — `from envshed import load_env; load_env(env="production")` populates `os.environ` from the live vault, so existing `os.environ["DATABASE_URL"]` reads keep working.
- **Sync and async** — the same client exposes `Client` and `AsyncClient` so FastAPI and Django both work without wrapping calls.
- **Local cache** — opt-in on-disk cache for restricted networks, encrypted with the same envelope the CLI uses.

## Workaround today

Two patterns work in production today and will keep working after the SDK ships.

### Option 1 — `envshed run` wraps your Python entry point

The cleanest pattern. No code changes — `envshed run` injects every secret as an env var, your code keeps reading `os.environ["DATABASE_URL"]`.

```bash
envshed run -e production -- python manage.py runserver
envshed run -e production -- uvicorn app.main:app
envshed run -e production -- python scripts/backfill.py
```

This works for one-off scripts, web servers, Celery workers, and anything else that reads from `os.environ` at startup.

### Option 2 — `envshed pull` writes a file `python-dotenv` already understands

If you already use [`python-dotenv`](https://pypi.org/project/python-dotenv/) and want to keep the import:

```bash
envshed pull -e production
```

That writes `.env` in the same `KEY=value` shape `python-dotenv` already reads.

Then in code:

```python
from dotenv import load_dotenv
load_dotenv()
```

This is the lowest-friction migration path for an app already using `python-dotenv` — you replace the source of truth, not the loader.

### Option 3 — call the REST API directly

For workers running in restricted environments where you cannot install the CLI, the REST API returns the same payload the CLI uses. See the existing curl examples in [snapshots](../features/snapshots) and [service tokens](../features/service-tokens) for the request shape.

## Want this sooner?

Python is on the [public roadmap](https://envshed.com/roadmap) right after the Vercel integration. If the SDK would unblock you, email [contact@envshed.com](mailto:contact@envshed.com?subject=Python%20SDK%20%2B1) with a line about your stack (Django, FastAPI, Flask, scripts, something else) — it helps us prioritize the API surface to ship first.

## Related

- [`envshed run`](../cli/run) — the CLI command both workarounds rely on
- [`envshed pull`](../cli/pull) — for the `dotenv` file pattern
- [Service tokens](../features/service-tokens) — what to give your worker pods
- [Public roadmap](https://envshed.com/roadmap)
