Skip to main content

Environment variable helpers

Project description

Roskarl

Is a tiny module for environment variables.

For pipeline configuration via environment variables, see Marshal.

Requires

Python 3.11.0+

How to install

pip install roskarl

Example usage

from roskarl 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: Special characters in passwords 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, formatted as:

postgresql://username:password@hostname:5432/database_name

The DSN object exposes the following attributes:

Attribute Type Example
scheme str postgresql
host str hostname
port int 5432
username str username
password str password
database str database_name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roskarl-3.0.3.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

roskarl-3.0.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file roskarl-3.0.3.tar.gz.

File metadata

  • Download URL: roskarl-3.0.3.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for roskarl-3.0.3.tar.gz
Algorithm Hash digest
SHA256 d66188753d3e402dda0b5be7bf67631ec50337d41a5cf9d65896ee4f991624cd
MD5 8ac708fbd21a8acd4d3871ba98219acc
BLAKE2b-256 becfe851149091539b77d71d69696613e7b793376da70b9715813587f520d3bd

See more details on using hashes here.

File details

Details for the file roskarl-3.0.3-py3-none-any.whl.

File metadata

  • Download URL: roskarl-3.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for roskarl-3.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fdcc8edcfaee2b6e663843d9358b4ecc45b27ea76bb62d1d34c55cd78fcc94fd
MD5 eb0fcf5b7f6e4c3f60674436da3f4663
BLAKE2b-256 8c509642d83376af818139a8df026ff0c92cd5f5c3e97750b0e6f0a3d5f3a7e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page