You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

loadenv

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadenv

Automatically load environment variables into structured Python data

0.1.1
pipPyPI
Maintainers
1

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}"})

Keywords

env

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts