Skip to main content

A completely unnecessary multitool module.

Project description

multinut

The multitool nobody asked for. Includes stuff and so.


multinut.env

A simple but flexible environment loader.

Supports .env file parsing with optional mode suffixes (e.g. .env.production, .env.testing, etc.), lazy loading, and dynamic access.

Features

  • Mode-based config support (.env.production, .env.testing, etc.)

  • Access via:

    • env["KEY"]
    • env.get("KEY", ...)
    • env.KEY
  • Optional type casting (str, bool, list, dict, etc.)

  • Sane default handling

  • Does not mutate os.environ


Use cases

  • Loading .env files in mode-aware Python projects
  • Separating secrets and configs by deployment context
  • Dynamically reading values like env.DB_URL, env.get("DEBUG", default=False, cast=cast_bool)
  • Avoiding os.environ pollution

Basic Example

from multinut.env import Environment, Modes

env = Environment(env_file_name=".env", mode=Modes.DEVELOPMENT)

print(env.get("DEBUG", default=False))
print(env["API_KEY"])
print(env.DB_URL)

Given a .env.development file:

DEBUG=true
API_KEY=secret
DB_URL=https://example.com

Smart Casts Example

from multinut.env import (
    Environment, cast_bool, cast_int, cast_float,
    cast_list, cast_tuple, cast_dict, cast_none_or_str
)

env = Environment()

print("INT:", env.get("PORT", cast=cast_int))                      # -> int
print("FLOAT:", env.get("PI", cast=cast_float))                    # -> float
print("BOOL:", env.get("ENABLED", cast=cast_bool))                 # -> bool
print("LIST:", env.get("NUMBERS", cast=cast_list))                 # -> list[str]
print("TUPLE:", env.get("WORDS", cast=cast_tuple))                 # -> tuple[str]
print("DICT:", env.get("CONFIG", cast=cast_dict))                  # -> dict
print("NONE_OR_STR:", env.get("OPTIONAL", cast=cast_none_or_str))  # -> None or str

Example .env:

PORT=8080
PI=3.1415
ENABLED=yes
NUMBERS=1,2,3
WORDS=hello,world,test
CONFIG={"timeout": 30, "debug": true}
OPTIONAL=null

Included Cast Helpers

All built-in cast functions handle common edge cases:

Cast Function Description
cast_str Ensures string
cast_int Converts to integer
cast_float Converts to float
cast_bool Accepts 1, true, yes, on, etc.
cast_list Comma-split list
cast_tuple Comma-split, converted to tuple
cast_dict Parses JSON string into dictionary
cast_none_or_str Returns None if value is null or None

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

multinut-0.2.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

multinut-0.2.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file multinut-0.2.2.tar.gz.

File metadata

  • Download URL: multinut-0.2.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for multinut-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c81d8d584eb42062daf28aeea58a4d74f9490413cd477610691ac5b11d4cd7b1
MD5 49084097ae03bff996dac617d51ac00d
BLAKE2b-256 7200c5998d1e6afa3c0aac14c5ee12c9d87c5ebd452922d46ee2f6d9e27eec73

See more details on using hashes here.

File details

Details for the file multinut-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: multinut-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for multinut-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 896881ecc769452d8f24c42deaacaf7746ddbde169dea347785c41a19c4edea6
MD5 02202a3def5ced1865d81792e1358766
BLAKE2b-256 7490aeb993e98dad306b6865af8d53dd276cdca3583bad61ab15d27bf2f162ef

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