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 # note that schemas work with any class that annotates its constructor, dataclass is used for simplicity
class ConnectionSetting:
host: str
port: int
user: Optional[str]
password: Optional[str]
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.1.0.tar.gz
(10.9 kB
view details)
Built Distribution
envolved-0.1.0-py3-none-any.whl
(12.7 kB
view details)
File details
Details for the file envolved-0.1.0.tar.gz
.
File metadata
- Download URL: envolved-0.1.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.0-1032-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5269f4de98d461dfe6da46c32bb87c171689e52e31f13b8c1caf93395ee193d2 |
|
MD5 | 4aba0a52ae6958b7d4586be9f66370e7 |
|
BLAKE2b-256 | 92c16a8ece1cf5ca702aad639ff6a06fb2dd199051185c923bb2f6ebee2fc097 |
File details
Details for the file envolved-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: envolved-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.0-1032-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb2c20a808e22384b0b117dd0df9c39981c81e98f093ee0ac58c3db7c27d62c5 |
|
MD5 | 1e1bc2ba5555fe9325e17d9bf81b802f |
|
BLAKE2b-256 | f1e6fc7bc2680c0cc0407a00d4f08f1cac76d8e5c84fbe0532c608043f724287 |