Skip to main content

load-env-vars-at-startup

Latest Commit
Package version

To understand the motivation behind this package, you might want to read about fail fast.

What this package does is to make sure you are reading all the environment variables at startup.

Example

Consider that you have a folder with the following structure:

app/
├── __init__.py
└── main.py

Inside of main.py you have:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def index():
    name = os.environ["APP_NAME"]
    return {"message": f"Hello, {name}!"}

If you run this application, it will run without any problem, but if you forget to set the APP_NAME environment variable, you will get an error when you try to access the / endpoint.

To avoid this, you can use this package.

If you decide to use it, your folder structure will look like this:

app/
├── __init__.py
├── main.py
└── config.py

Your config.py will look like this:

from pydantic import BaseSettings

class Settings(BaseSettings):
    APP_NAME: str

settings = Settings()

And your main.py will look like this:

from fastapi import FastAPI
from app.config import settings

app = FastAPI()

@app.get("/")
def index():
    name = settings.APP_NAME
    return {"message": f"Hello, {name}!"}

Installation

You can install load-env-vars-at-startup via pip:

pip install load-env-vars-at-startup

Usage

levas DIR

Where DIR is the directory of your application.

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for load-env-vars-at-startup 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for load-env-vars-at-startup 0.1.0
File Size Uploaded
load_env_vars_at_startup-0.1.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for load-env-vars-at-startup 0.1.0
File Interpreter ABI Platform
load_env_vars_at_startup-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / load_env_vars_at_startup-0.1.0.tar.gz

Download URL load_env_vars_at_startup-0.1.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
487ae7ec01e726ae59bbbc480c0b372831035b44d0770717af2b8c85cec771d3
BLAKE2b-256 checksum
How to use checksums
8e8d0367cd392a579874f5ce44886008af5b9e85654f2b050454ceace93f9246
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / load_env_vars_at_startup-0.1.0-py3-none-any.whl

Download URL load_env_vars_at_startup-0.1.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4c3733819366282f2a0b651ec6e15d24a3978eee7149a43a96eda1aff3b21fd
BLAKE2b-256 checksum
How to use checksums
80bac1bdb5716e324905a34063d3be6417ead1a1a7e561ae17338f35cf803095
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page