Skip to main content

Manage and get process.env

Project description

env-get

Manage and retrieve env variables in Python.

Install

$ pip install env-get

Usage

from env_get import env, EnvRequiredError

port = env('SERVER_PORT', env.integer, 80)

env(key, converter, defaults) -> Any

def Converter(v: Any, key: str, is_default: bool) -> Any:
  • key str: The environment variable key.
  • converter Optional[Converter | List[Converter]] A converter function or a list of converter functions.
    • v the current value of the variable
    • key the key of the environment variable
    • is_default True means the environment variable is not set, even not set as FOO=
  • defaults Opitonal[Any] The optional default value if the environment variable is not found.

Returns Any the retrieved env variable.

Built-in Converter Functions

  • env.boolean: Converts the value to a boolean. Treats 'true', '1', 'Y', 'y', 'yes', and True as True.
  • env.integer: Converts the value to an integer. Returns 0 if conversion fails.
  • env.required: Ensures that the environment variable is set. Raises a EnvRequiredError if not.

Examples

Boolean Conversion

debug_mode = env('DEBUG_MODE', env.boolean, False)

Integer Conversion

port = env('PORT', env.integer, 8080)

Required Variable

from env_get import env, EnvRequiredError

try:
    api_key = env('API_KEY', env.required)
except RangeError as e:
    print(e)  # Output: env "API_KEY" is required

Handling Multiple Converters

You can apply multiple converters by passing a list of converter functions.

value = env('SOME_VAR', [env.required, env.integer], 10)

License

MIT

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

env_get-1.0.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

env_get-1.0.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file env_get-1.0.4.tar.gz.

File metadata

  • Download URL: env_get-1.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for env_get-1.0.4.tar.gz
Algorithm Hash digest
SHA256 ce3023310151430ead4a84b21fed0255716c727194927279deb45c118578e2f5
MD5 b39d56d105627096fbfa3ce174bd0c50
BLAKE2b-256 f17aab2522f01869af3b3783c6fefd26d9acac24ef94e8ca6a2d6e89500ded0f

See more details on using hashes here.

File details

Details for the file env_get-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: env_get-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for env_get-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 169e93a98b33684832393c62772dccec5c2499f386684331b1df4f11d8c431f3
MD5 6ab251d6b8e93adbb5f2d4efe69fe230
BLAKE2b-256 02dcfa299d2a72d69ec53e25982c6e78bcf3e7663c5eaf12a8149dd5cea2c48e

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