No project description provided
Project description
Envolved
Envolved is a library to make environment variable parsing powerful and effortless.
from envolved import EnvVar
# create an env var with an int value
foo: EnvVar[int] = EnvVar('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 JsonParser
foo = EnvVar('FOO', type=JsonParser(List[float]))
foo.get() # now we will parse the value of FOO as a JSON list, and ensure that all its inner values are numbers
# we can also use schemas to combine multiple environment variables
from envolved import Schema
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]
# note that schemas work with any factory or class that annotates its constructor, dataclass is used for simplicity
class ConnectionSettingSchema(Schema, type=ConnectionSetting):
host = EnvVar('hostname')
# we now define an env var inside the schema. Its suffix will be "hostname", and its type will be inferred from the
# type's annotation
port = EnvVar() # if we like the parameter name as the env var suffix, we can leave the env var empty
user: str = EnvVar('username') # we can annotate the schema members to override the type inference
password = EnvVar(type=str, default=None) # we can set a default to show that the type var may be missing
connection_settings: EnvVar[ConnectionSetting] = EnvVar('service_', type=ConnectionSettingSchema)
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-0.3.0.tar.gz
(11.6 kB
view details)
Built Distribution
envolved-0.3.0-py3-none-any.whl
(13.4 kB
view details)
File details
Details for the file envolved-0.3.0.tar.gz
.
File metadata
- Download URL: envolved-0.3.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.7 Linux/5.4.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35e3e997b8cf159f5e76f5ddbe114de28f4f04ac7c81ec5c8e43d90a6532f8ba |
|
MD5 | 24bf785d50a12e805b70046801ae0e8b |
|
BLAKE2b-256 | 9b24194f6c42a1ffcaf1811d67d3b3cbaa0ca9356217e2f978a0345a6665012b |
File details
Details for the file envolved-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: envolved-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.7 Linux/5.4.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb7709b13de28061b294b08bba2dc21ca8a3fc06cab198f2a16d45ccf3a262ca |
|
MD5 | bd069aaa9e280135b3234f6f4cb1a79d |
|
BLAKE2b-256 | 2a088d528cc7d3e9ab58b58ee4ce6a2b5e6ace32306e74004925ad13dada4d51 |