Skip to main content

Awesome env_fields created by dvvolynkin

Project description


env_fields

codecov CI

Dataclass fields with getting values from environment by default

Install it from PyPI

pip install env_fields

Usage

import os
from dataclasses import field, dataclass
from env_fields import (
    env_field_int,
    env_field_str,
    env_field,
)


@dataclass
class SomeClass:
    attribute_1: int = field()
    attribute_2: int = env_field_int('SOME_INT_ENVIRONMENT_VARIABLE')
    attribute_3: str = env_field_str('SOME_STR_ENVIRONMENT_VARIABLE')
    attribute_4: str = env_field_str(
        'SOME_STR_ENVIRONMENT_VARIABLE_THAT_NOT_SET',
        default="hello, world"
    )
    attribute_5: int = env_field("SOME_CUSTOM_TYPE_ENV_VARIABLE", float, init=False)

Let's create some dataclass!

>>> os.environ['SOME_INT_ENVIRONMENT_VARIABLE'] = "1234"
>>> os.environ['SOME_STR_ENVIRONMENT_VARIABLE'] = "hello, world 1"
>>> os.environ['SOME_CUSTOM_TYPE_ENV_VARIABLE'] = "2.59"
>>> SomeClass(12)
SomeClass(
    attribute_1=12,
    attribute_2=1234,
    attribute_3='hello, world 1',
    attribute_4='hello, world',
    attribute_5=2.59,
)

Development

Read the CONTRIBUTING.md file.

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_fields-0.2.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

env_fields-0.2.0-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

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