Skip to main content

yapeco

yapeco (Yet Another Python Envvar Config Object) is a tiny utility module to access .env (and otherwise environment-defined) config values in a structured way through a Python object. Created for the dual purpose of easily requiring/defaulting/casting environment variables at startup time for typical Python microservices & being able to autocomplete envvars in my editor.

Features & Limitations

  • Case-insensitive + snake-case (i.e. SNAKE_case) field names
  • Primitives such as str, bool, int and float are supported (no guarantees with float though, because, well... floating point)
  • Assuming use of the above primitives and enums, supports Optional[*] types (and by extension Union[*,None]), but no others from typing
  • Default values through class variable assignment; assumed to be None for optional types
  • Will (intentionally) raise a RuntimeError if there is no value set and no default value
  • Common boolean config formats (i.e. VAR=0/1/true/false/True/False) work as expected
  • Enums as well as str/int-literal unions are checked and parsed out
  • Unchecked JSON objects can be used too if you really want that for some reason lmao

Usage

Installation (PyPI):

pip3 install yapeco

Simple example:

# -- [mock environment] ---------------------------
API_KEY=abc123
DELAY_MSEC=18
FEATURE_A_ENABLED=false
FEATURE_B_ENABLED=1
VALUE=thing2
VALUE2=8
# --- contrived_config.py -------------------------

from enum import Enum, unique
from yapeco import BaseEnvironment as Env

@unique
class MyValue(Enum):
    THING1 = "thing1"
    THING2 = "thing2"

class Config(Env):
    api_key: str
    delay_msec: int
    feature_a_enabled: bool
    feature_a_flags: str = "-a -b -c"
    feature_b_enabled: bool
    feature_b_flags: Optional[str]
    value: MyValue
    value2: Literal["abc", "def", 7, 8]


# --- main.py -------------------------------------

from config import Config

Config.api_key # "abc123"
Config.delay_msec # 18
Config.feature_a_enabled # False
Config.feature_a_flags # "-a -b -c"
Config.feature_b_enabled # True
Config.feature_b_flags # None
Config.value # MyValue.THING1
Config.value2 # 7

# ...
# API_KEY=def456
# FEATURE_B_ENABLED=false

Config.refresh() # update environment

Config.api_key # "def456"
Config.feature_b_enabled # False

Development

Requires poetry.

poetry install  # install dependencies
poetry build  # build package
poetry run pytest .  # run tests
poetry run pyright .  # run type checks

Extra

Pedantic note:

As in Smalltalk, classes themselves are objects.

—The Literal Python Documentation

Metadata

Release files for yapeco 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yapeco 0.1.5
File Size Uploaded Provenance Actions
yapeco-0.1.5.tar.gz 4.0 kB Without provenance Details for yapeco-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yapeco 0.1.5
File Interpreter ABI Platform Actions
yapeco-0.1.5-py3-none-any.whl Python 3 none any Details for yapeco-0.1.5-py3-none-any.whl

Total release size: 8.4 kB

Release files / yapeco-0.1.5.tar.gz

Download URL yapeco-0.1.5.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
261aeab98e9daf49313d43bcf470b70c96c67cb208b549458df2e69b8c350b4a
BLAKE2b-256 checksum
How to use checksums
370cf607c77c7b0aea520e21b3e6da6cf3ba43742eafe8570b92a8eef0be9e3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.5 Darwin/24.1.0

Release files / yapeco-0.1.5-py3-none-any.whl

Download URL yapeco-0.1.5-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75eff14439c159fb7f50effd6f61fbf70f71f1fe4bb5b329f56cf9771c4eb674
BLAKE2b-256 checksum
How to use checksums
9a65ef1ec374c4aa32a6c756aec2506988f3d498fae00020faf317ee41b4e4c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.5 Darwin/24.1.0

Security for yapeco 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page