Skip to main content

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


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.4.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

envolved-0.4.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file envolved-0.4.0.tar.gz.

File metadata

  • Download URL: envolved-0.4.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.7 Linux/5.4.0-1039-azure

File hashes

Hashes for envolved-0.4.0.tar.gz
Algorithm Hash digest
SHA256 44e8cee5c6506e45683d494b00132b6eabdb1806a6dbe345f3cb378f52157afc
MD5 a49e1f8ad46674449a3b6d98cbf95342
BLAKE2b-256 2812b7b4de4a0412288a503f877f48f03be230a2ea34724f8da121b0fed90162

See more details on using hashes here.

File details

Details for the file envolved-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: envolved-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.7 Linux/5.4.0-1039-azure

File hashes

Hashes for envolved-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 796368bef079f9ac0521f2bceda628c8169c7074484380cf0c12982701660c0e
MD5 d7ab83d571c99eb1999f84cc1acfac34
BLAKE2b-256 c4da2a8e85fb525ff0d3b0f0e74c0c9247116e0122a8c36d48e657d0c8503bfe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page