Skip to main content

Krywok Kit Environment is a developer-centric environment variable manager. It leverages the Krywok Pipeline engine to treat environment variables not just as strings, but as strictly validated and transformed data structures.

Project description

Krywok Logo

Krywok Kit Environment is a developer-centric environment variable manager. It leverages the Krywok Pipeline engine to treat environment variables not just as strings, but as strictly validated and transformed data structures.

Installation

pip install krywok-kit-env

Why use this?

Standard os.environ.get returns strings and provides no validation. Krywok Kit Environment allows you to:

  1. Validate length, patterns, and types immediately.
  2. Transform values (lowercase, strip, cast) during retrieval.
  3. Parse JSON structures stored in environment strings automatically.
  4. Enforce existence for missing variables.

Usage Example

from krywok_kit_env import EnvironmentVariable
from pipeline import Condition, Match, Transform

# Set the path for your .env file
EnvironmentVariable.dotenv_path = ".env"

# Define a validated environment variable
# This will raise an exception if the key is missing or validation fails
SECRET_KEY = EnvironmentVariable[str](
    name="SECRET_KEY",
    type=str,
    conditions={
        Condition.ExactLength: 32
    },
    matches={
        Match.Text.Letters: None
    },
    transform={
        Transform.Lowercase: None
    }
)

# Access the processed value
print(SECRET_KEY.get)

# You can call to get the raw value (Clean variable)
API_PORT: int = EnvironmentVariable[int](name="API_PORT", type=int)()

Pythonic Access Patterns

You don't have to manually call .get every time. The EnvironmentVariable instance implements magic methods to make your code cleaner:

  • Direct Comparison: Use == to compare the variable directly with a value.

    if SECRET_KEY == "expected_hash_value":
        ...
    
  • Boolean Logic: Use it directly in if statements to check if the value is truthy.

    DEBUG_MODE = EnvironmentVariable[bool](name="DEBUG", optional=True)
    
    if DEBUG_MODE:
        print("Debug is enabled")
    
  • String Conversion: Use it directly in f-strings or print().

    print(f"API_URL: {API_URL}")
    
  • Callable shorthand: Call the object like a function to get the value.

    current_key = SECRET_KEY()
    

Core Features

  • Strict Typing: Use Python generics EnvironmentVariable[T] for better IDE support and type safety.
  • JSON Ready: Built-in json.loads support for complex environment configurations.
  • Pipeline Integration: Full access to the Pipeline execution flow (Type Check -> Setup -> Conditions -> Matches -> Transformations).
  • Singleton .env Loading: The .env file is loaded once and shared across all instances.

Documentation

This package uses the Krywok Pipeline logic for its core processing. To learn more about available conditions, matches, and transformations, visit Official Documentation

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

krywok_kit_env-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

krywok_kit_env-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file krywok_kit_env-0.1.0.tar.gz.

File metadata

  • Download URL: krywok_kit_env-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krywok_kit_env-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2b972493fe2c6b838f8bce9aac31075a31d7345c92294981ab90006162cec436
MD5 03725f0217cd10fdf9c33b05ade1d6bd
BLAKE2b-256 a75270bcd003bff85ffe5da5893ca0248052e2ad87536dcfb5c806881e446f7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for krywok_kit_env-0.1.0.tar.gz:

Publisher: python-publish.yml on Krywok/krywok-kit-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krywok_kit_env-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: krywok_kit_env-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krywok_kit_env-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cec7e1306d7cf4a454a919d9b4b0a33e22a2e91077e1e1390b51a28271949ca5
MD5 9d8ee73521734af754b16423d41dd924
BLAKE2b-256 74398c8ceedce60debe2e215b7d2e9610be1adf9adb177afb22bccd71531c7d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for krywok_kit_env-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on Krywok/krywok-kit-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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