Skip to main content

Automatically load environment variables into structured Python data

Project description

loadenv

Automatically load environment variables into structured Python data

Loadenv makes it easy to pull environment variables into your program. It centralizes and hides the task of loading environment variables and asserting necessary variables are set, while assigning default values for those that are not required.

Loaded variables are cast to python objects based on type annotations and stored as identifiers, not strings. So typo bugs are easier to catch and names are easier to autocomplete. It does all this during startup, making bad invocations quit as soon as possible and with a clear error message, rather than deep in business logic from strange Exceptions.

Getting Started

Define an EnvEnum where each member is named exactly as the environment variable you wish to capture. It should be annotated with the type you would like the member to be. You will have to assign some value to the member to actually create it. For required environment variable this value does not matter; values such as () or ... are good choices.

from loadenv import EnvEnum


# values are taken from the environment when the class is created
class Secrets(EnvEnum):
    USERNAME: str = ()
    USERPASS: str = ()
    USERAPIKEY: str = ()


# later on
requests.post(prod, headers={"Authorization": f"TOK:{Secrets.USERAPIKEY}"})

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

loadenv-0.1.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

loadenv-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file loadenv-0.1.1.tar.gz.

File metadata

  • Download URL: loadenv-0.1.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for loadenv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8dde4a80cf733323880c118659685d822f9d1311fa15b3d7e1e2aa28223aba29
MD5 f93e47f6c9b59f47e0c751c3335c344d
BLAKE2b-256 d7a24ef0013d1683cdcd29ea254e3a02ac43f25323842fc8d59983eb17608f47

See more details on using hashes here.

File details

Details for the file loadenv-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: loadenv-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for loadenv-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e06a1d86ea1ad89a96aeb470d27de8d569a980ad7c6fd0dd0ee416cc11919853
MD5 a4dab4cec4da4b23a54df20636bee999
BLAKE2b-256 d0bae29b2a5d12d5fad9c037ad7d5c3dffb22864d6511310bffa414c56408995

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