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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file env_fields-0.2.0.tar.gz.

File metadata

  • Download URL: env_fields-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for env_fields-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1876d1ef570340956e5fec07097555e8ab4efc89ea39b0a363759f9c163d7083
MD5 e4fd650221f56b0ff642deea509dad9c
BLAKE2b-256 e17f7cbc3e64d75451879af24a3ef825aab01e5c38e3698b31f040ad9a9975f2

See more details on using hashes here.

File details

Details for the file env_fields-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: env_fields-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for env_fields-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c393b8f6b660332e6af1300591fef2c22bf5154a2f60613472d24b0ed5698928
MD5 1b6e4f4489e0316beed9c6520e5d6155
BLAKE2b-256 efc60208cfdc8786269fb54bccc51448f1748873d44eb1bbba413598c58f06b6

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