Skip to main content

🦕 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 ❤️

Release files for envtyped 0.1.1

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

Source distribution (sdist)

Source distribution for envtyped 0.1.1
File Size Uploaded
envtyped-0.1.1.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envtyped 0.1.1
File Interpreter ABI Platform
envtyped-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / envtyped-0.1.1.tar.gz

Download URL envtyped-0.1.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d220c784e35ce72d2157fd1e4fd9307e42734f4e9796594ec7721de5443a3c90
BLAKE2b-256 checksum
How to use checksums
76454afc9ddac4d88d3cabea858fbe60d276eb490dc36a71bb194c2c7b1be9f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

Release files / envtyped-0.1.1-py3-none-any.whl

Download URL envtyped-0.1.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12e9f8ac1ccc9f1a0194bc46d561bcbecf240cb3691ec3d43f0d59f23d9d1c51
BLAKE2b-256 checksum
How to use checksums
db12686dc4c980736fb26fe8ad2c659d932a4dc632f15bb997be031aaaf73eb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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