Envlet for Python
inject() fills os.environ before your app starts. Django, FastAPI, Flask, and plain scripts read values the way they always did.
Set up
Three steps. The host keeps one secret and everything else arrives at boot.
- 01
Install
One package. Django, FastAPI, Flask, and plain scripts.
Terminalpip install envlet - 02
Set one secret
ENVLET_TOKEN on the server, container, or function.
Python / production / environment variablesENVLET_TOKEN envlet_•••••••• the only secret the host keeps DATABASE_URL •••••••• moved to Envlet STRIPE_KEY •••••••• moved to Envlet SENTRY_DSN •••••••• moved to Envlet - 03
Inject at boot
Call inject() at the top of your entrypoint.
main.pyimport os from envlet import inject inject() stripe.api_key = os.environ["STRIPE_KEY"]
Three calls
inject for most apps. load when you want a map. get when you want one value.
import os
from envlet import inject
inject()
stripe.api_key = os.environ["STRIPE_KEY"]Typed
envlet types writes this file from the variables in your environment, with a load() that fills the shape below. Run it with --check in CI and a renamed variable fails the build.
envlet types
envlet types --check# Generated by envlet types for the "production" environment.
from typing import Any, Literal, Optional, Tuple, TypedDict, cast
import envlet as _envlet
Env = TypedDict(
"Env",
{
"DATABASE_URL": str,
"DEBUG": bool,
"FLAGS": Optional[Any],
"MODE": Literal["dev", "prod"],
"PORT": int,
"STRIPE_KEY": str,
},
)
Name = Literal["DATABASE_URL", "DEBUG", "FLAGS", "MODE", "PORT", "STRIPE_KEY"]Questions
Will my app start if Envlet is down?
No. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.
What does the host need?
One variable, ENVLET_TOKEN. Everything else arrives at boot.
Can I still set some values on the Python host?
Yes. A value the host already set wins. Pass override if you want Envlet to win instead.