Skip to main content

Strong typing for your environment variables

Project description

🦕 envtyped

This library is heavily inspired by python-decouple. Main goal is to provide a simple way to load environment variables, with type hinting, for my FastAPI projects.

📝 Table of Contents

📦 Installation

pip install envtyped

🚀 Usage

from envtyped import config

# Get environment variable, no need to do anything else, .env file is lazy loaded
SECRET_KEY = config.get("MY_ENV_VAR") # str

# You can cast the value to another type
DELAY_IN_SECONDS = config.get("DELAY_IN_SECONDS", cast=int) # int

# You can also use a custom function to cast the value
DELAY = config.get("DELAY", cast=lambda x: datetime.fromtimestamp(int(x))) # datetime

# If you need to, you also can use a custom class to cast the value, that can be constructed from a string
class Employee:
    def __init__(self, name: str) -> None:
        self.name = name.capitalize()

    def hello(self) -> str:
        return f"Hello {self.name}"


EMPLOYEE = config.get("EMPLOYEE", cast=Employee) # Employee
EMPLOYEE.hello()
# -> Hello John

# By default all env variables are required, but you can also set a default value
SECRET_KEY = config.get("SECRET_KEY", default="default_secret_key")

# Or you can set a value to be optional
SECRET_KEY = config.get("SECRET_KEY", optional=True) # Optional[str]


# This library provides a helpers to read csv 
from envtyped import Csv

AVAILABLE_LANGUAGES = config.get("AVAILABLE_LANGUAGES", cast=Csv()) # List[str]

# Csv can also be used to cast a list of string to a list of class
class Language:
    def __init__(self, name: str) -> None:
        self.name = name

AVAILABLE_LANGUAGES = config.get("AVAILABLE_LANGUAGES", cast=Csv(cast=Language)) # List[Language]

# Choise is a helper to limit the value to a list of choice
from envtyped import Choise

USER_LANGUAGE = config.get("USER_LANGUAGE", cast=Choise(["en", "fr"])) # str
USER_CURRENCY = config.get("USER_CURRENCY", cast=Choise(["usd", "eur"], default="usd")) # str

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

With ❤️

Project details


Download files

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

Source Distribution

envtyped-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

envtyped-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file envtyped-0.1.1.tar.gz.

File metadata

  • Download URL: envtyped-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for envtyped-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d220c784e35ce72d2157fd1e4fd9307e42734f4e9796594ec7721de5443a3c90
MD5 5883ebf2e6ad629bdc15e47c9c3b63ac
BLAKE2b-256 76454afc9ddac4d88d3cabea858fbe60d276eb490dc36a71bb194c2c7b1be9f8

See more details on using hashes here.

File details

Details for the file envtyped-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: envtyped-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for envtyped-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12e9f8ac1ccc9f1a0194bc46d561bcbecf240cb3691ec3d43f0d59f23d9d1c51
MD5 bdfc5a75cf198dfddc20a4f3cd80c637
BLAKE2b-256 db12686dc4c980736fb26fe8ad2c659d932a4dc632f15bb997be031aaaf73eb9

See more details on using hashes here.

Supported by

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