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 !
Release files for antares-dotenv 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| antares_dotenv-1.1.0.tar.gz | 2.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| antares_dotenv-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.4 kB
Release files / antares_dotenv-1.1.0.tar.gz
| Download URL | antares_dotenv-1.1.0.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27a964a5645d6c6d3ce3ec2196f1ce52b799e4a25db382e51980442fd497d53e
|
|
BLAKE2b-256 checksum How to use checksums |
d0f0a30a4c8120bbcf71fc7f02a84e9d4b99bac8c24218395eb4a607de05d6fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.11.2 Linux/6.12.32-amd64
|
Release files / antares_dotenv-1.1.0-py3-none-any.whl
| Download URL | antares_dotenv-1.1.0-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8864324da46515eb8c7e70efd43db6b05ab0a7179653f61e83b18bd60b248918
|
|
BLAKE2b-256 checksum How to use checksums |
7e7339436bdfc1c2eef97398bffe2d1f8eb2b633a04cbf9bda17400b98952bcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.11.2 Linux/6.12.32-amd64
|