env-item is a lightweight Python package for working with environment configuration items.
Project description
ENV-Item
Description
env-item is a lightweight Python package for working with environment configuration items.
It provides a simple API to define, access, and manage environment values in Python applications. The core aim is to make environment interaction clear and explicit while fitting seamlessly into modern Python projects.
Installation
pip install env-item
or
uv add env-item
Usage
Importing
from env_item import EnvItem
Basic
from env_item import EnvItem
from dotenv import load_dotenv
load_dotenv()
var = EnvItem("MY_ENV_VAR").as_str()
print(var)
Advenced
from env_item import EnvItem
from dotenv import load_dotenv
load_dotenv()
class Config:
DEBUG = EnvItem("DEBUG").default(False).as_bool()
class Database:
HOST = EnvItem("DB_HOST").default("localhost").as_str()
PORT = EnvItem("DB_PORT").default(5432).as_int()
USER = EnvItem("DB_USER").required().as_str()
PASSWORD = EnvItem("DB_PASSWORD").required().secret().as_str()
NAME = EnvItem("DB_NAME").required().as_str()
class API:
KEY = EnvItem("API_KEY").required().secret().as_str()
TIMEOUT = EnvItem("API_TIMEOUT").default(30).as_int()
print(Config.DEBUG)
print(Config.Database.HOST)
print(Config.Database.PORT)
print(Config.Database.USER)
print(Config.Database.PASSWORD) # This will not print the value because it is marked as secret; the value is replaced with ******
print(Config.Database.NAME)
print(Config.API.KEY)
print(Config.API.TIMEOUT)
Constrains
required
if variable is not set, it will raise an error.
VAR = EnvItem("MY_ENV_VAR").required()
default
if variable is not set, it will return the default value.
VAR = EnvItem("MY_ENV_VAR").default("default_value")
secret
if variable is marked as secret, it will not be printed in logs or error messages.
VAR = EnvItem("MY_ENV_VAR").secret()
Get value
as_str
VAR = EnvItem("MY_ENV_VAR").as_str()
print(VAR)
as_int
VAR = EnvItem("MY_ENV_VAR").as_int()
print(VAR)
as_bool
VAR = EnvItem("MY_ENV_VAR").as_bool()
print(VAR)
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 env_item-0.1.1.tar.gz.
File metadata
- Download URL: env_item-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26d6c63d48f78050efd7230879ff690679768d0eee00fb6a4258e4f4a79ba590
|
|
| MD5 |
b37e142cc45ae67a0833a3ffb478a596
|
|
| BLAKE2b-256 |
e0980ea91ed1f350cfb3f134d1c30b94faa0d992c93609008fd27194a3321ed8
|
File details
Details for the file env_item-0.1.1-py3-none-any.whl.
File metadata
- Download URL: env_item-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b6a9a970c47fd00428501552cc7d7dcb988c6125ec550d3493dc67e6884ee25
|
|
| MD5 |
4fd4cd0da572982b1f349a5bcd39abf1
|
|
| BLAKE2b-256 |
92d4b374cbda0236f7dd1ee9af131bd3fe2575d55ab17205d3b77d1f7e83f8c2
|