Environment variable helpers
Project description
Roskarl
Is a tiny module for environment variables.
Requires
Python 3.11.0+
How to install
pip install roskarl
Example usage
from roskarl.env import (
env_var,
env_var_bool,
env_var_cron,
env_var_float,
env_var_int,
env_var_iso8601_datetime,
env_var_list,
env_var_rfc3339_datetime,
env_var_tz,
env_var_dsn,
DSN
)
All functions return None if the variable is not set. An optional default parameter can be provided to return a fallback value instead.
value = env_var(name="STR_VAR", default="fallback")
str
value = env_var(name="STR_VAR")
returns str
bool
value = env_var_bool(name="BOOL_VAR")
returns bool — accepts true or false (case insensitive)
tz
value = env_var_tz(name="TZ_VAR")
returns str if value is a valid IANA timezone (e.g. Europe/Stockholm)
list
value = env_var_list(name="LIST_VAR", separator="|")
returns list[str] if value is splittable by separator
int
value = env_var_int(name="INT_VAR")
returns int if value is numeric
float
value = env_var_float(name="FLOAT_VAR")
returns float if value is a float
cron
value = env_var_cron(name="CRON_EXPRESSION_VAR")
returns str if value is a valid cron expression
datetime (ISO8601)
value = env_var_iso8601_datetime(name="DATETIME_VAR")
returns datetime if value is a valid ISO8601 datetime string — timezone is optional
2026-01-01T00:00:00
2026-01-01T00:00:00+00:00
datetime (RFC3339)
value = env_var_rfc3339_datetime(name="DATETIME_VAR")
returns datetime if value is a valid RFC3339 datetime string — timezone is required
2026-01-01T00:00:00+00:00
DSN
Note: if you use special characters in the password, these must be URL-encoded
from urllib.parse import quote
password = 'My$ecret!Pass@2024'
encoded = quote(password, safe='')
print(encoded) # My%24ecret%21Pass%402024 <--- use this
value = env_var_dsn(name="DSN_VAR")
returns DSN object if value is a valid DSN string
needs to be formatted like this:
postgresql://username:password@hostname:5432/database_name
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 roskarl-2.4.2.tar.gz.
File metadata
- Download URL: roskarl-2.4.2.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c72d3fd1cdcea7c392282ea5a443754486f7d5400a361ed051d5eb3226efd7d0
|
|
| MD5 |
b390aceafef5e7cf7bf5a07c1710aecf
|
|
| BLAKE2b-256 |
d914bb2e407e6523940ee08b9434dc98029f10f706a1adbf5e0f81517e00c217
|
File details
Details for the file roskarl-2.4.2-py3-none-any.whl.
File metadata
- Download URL: roskarl-2.4.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c535cdc91f1cecd5d1c31a33c848afc8875abbc764328ac0d2ba381cf05974d
|
|
| MD5 |
a35eb3c278e87e4b744fb8d8042e536f
|
|
| BLAKE2b-256 |
66846790d0fe43a354ff56c938a04bc26419428a07b08da350e3cf3a40b2b368
|