No project description provided
Project description
Envolved
Envolved is a library to make environment variable parsing powerful and effortless.
documentation: https://envolved.readthedocs.io/en/latest/
from envolved import env_var, EnvVar
# create an env var with an int value
foo: EnvVar[int] = env_var('FOO', type=int, default=0)
value_of_foo = foo.get() # this method will check for the environment variable FOO, and parse it as an int
# we can also have some more complex parsers
from typing import List, Optional
from envolved.parsers import CollectionParser
foo = env_var('FOO', type=CollectionParser(',', int))
foo.get() # now we will parse the value of FOO as a comma-separated list of ints
# we can also use schemas to combine multiple environment variables
from dataclasses import dataclass
@dataclass
# say we want the environment to describe a ConnectionSetting
class ConnectionSetting:
host: str
port: int
user: Optional[str]
password: Optional[str]
connection_settings: EnvVar[ConnectionSetting] = env_var('service_', type=ConnectionSetting, args={
'host': env_var('hostname'),
# we now define an env var as an argument. Its suffix will be "hostname", and its type will be inferred from the
# type's annotation
'port': env_var('port'),
'user': env_var('username', type=str), # for most types, we can infer the type from the annotation, though we can
# also override it if we want
'password': env_var('password', type=str, default=None) # we can also set a default value per arg
})
service_connection_settings: ConnectionSetting = connection_settings.get()
# this will look in 4 environment variables:
# host will be extracted from service_hostname
# port will be extracted from service_port, then converted to an int
# user will be extracted from service_username
# password will be extracted from service_password, and will default to None
# finally, ConnectionSetting will be called with the parameters
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
envolved-1.2.0.tar.gz
(16.3 kB
view details)
Built Distribution
envolved-1.2.0-py3-none-any.whl
(19.1 kB
view details)
File details
Details for the file envolved-1.2.0.tar.gz
.
File metadata
- Download URL: envolved-1.2.0.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.12.1 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14866250b2b38d9d672a7ccdd402fc251593e37a7690a92cafe37c46d225ea27 |
|
MD5 | b5c568c6e71a12d071a11ef2e4c1ce37 |
|
BLAKE2b-256 | b34b161fcd96d2383f3afbef24093bcdfe98fa3a5c9d088c50adade827172e2a |
File details
Details for the file envolved-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: envolved-1.2.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.12.1 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 262f69902bdd58173d7a9bb88894a5a2b444670bfdb1dd1012d79ce7d1ad4bd0 |
|
MD5 | 920591d5de1b5559d196d1dd06008dab |
|
BLAKE2b-256 | db2b4d2f439b689bcaa18cb07ecb1fe1c8f034f0dde5c40f4577c61781973d3c |