A minimal utility to load environment variables with automatic type casting.
Project description
antares-dotenv
A minimalistic and developer-friendly way to handle environment variables in Python. Just import env and start using it. No more boilerplate code for loading and parsing.
Installation
pip install antares-dotenv
Usage
Create a .env file in your project root:
# .env
# Strings
APP_NAME=My Awesome App
# Integers
PORT=8000
# Booleans
DEBUG=True
# Lists (comma-separated)
ALLOWED_HOSTS=localhost,127.0.0.1
# JSON
DATABASE_CONFIG={"user": "admin", "password": "secret"}
Now you can access these variables in your Python code:
# main.py
from antares_dotenv import env
# String
app_name = env("APP_NAME", default="My App")
print(f"App Name: {app_name}")
# Integer (auto-parsed)
port = env("PORT")
print(f"Port: {port} (type: {type(port).__name__})")
# Boolean (auto-parsed)
debug_mode = env("DEBUG")
print(f"Debug Mode: {debug_mode} (type: {type(debug_mode).__name__})")
# List (auto-parsed)
allowed_hosts = env("ALLOWED_HOSTS")
print(f"Allowed Hosts: {allowed_hosts} (type: {type(allowed_hosts).__name__})")
# JSON (auto-parsed to dict)
db_config = env("DATABASE_CONFIG")
print(f"Database User: {db_config['user']}")
# Using a default value for a missing key
secret_key = env("SECRET_KEY", default="a-very-secret-key")
print(f"Secret Key: {secret_key}")
Why antares-dotenv?
antares-dotenv is designed to reduce boilerplate and simplify your code.
Before (with python-dotenv and os):
import os
from dotenv import load_dotenv
load_dotenv()
port = int(os.getenv("PORT"))
debug = os.getenv("DEBUG").lower() == 'true'
hosts = os.getenv("ALLOWED_HOSTS").split(',')
After (with antares-dotenv):
from antares_dotenv import env
port = env("PORT")
debug = env("DEBUG")
hosts = env("ALLOWED_HOSTS")
antares-dotenv automatically handles the type casting for you, eliminating the need for manual type conversion and making your code cleaner, more readable, and less verbose.
[!Note]
antares-dotenvdepends onpython-dotenv
PS: This package is tailored to my specific needs !
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file antares_dotenv-1.1.0.tar.gz.
File metadata
- Download URL: antares_dotenv-1.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.2 Linux/6.12.32-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27a964a5645d6c6d3ce3ec2196f1ce52b799e4a25db382e51980442fd497d53e
|
|
| MD5 |
015a91d83733b991716d44985e3e9e20
|
|
| BLAKE2b-256 |
d0f0a30a4c8120bbcf71fc7f02a84e9d4b99bac8c24218395eb4a607de05d6fe
|
File details
Details for the file antares_dotenv-1.1.0-py3-none-any.whl.
File metadata
- Download URL: antares_dotenv-1.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.2 Linux/6.12.32-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8864324da46515eb8c7e70efd43db6b05ab0a7179653f61e83b18bd60b248918
|
|
| MD5 |
9cada62d13e8d35ee1a4a43a6b3026ba
|
|
| BLAKE2b-256 |
7e7339436bdfc1c2eef97398bffe2d1f8eb2b633a04cbf9bda17400b98952bcd
|