Giter Club home page Giter Club logo

load-env-vars-at-startup's Introduction

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.

load-env-vars-at-startup's People

Contributors

kludex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

load-env-vars-at-startup's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.