Skip to main content

Typed environment variable parsing for Python. Zero dependencies. Pure stdlib.

Project description

pureenv

Typed environment variable parsing for Python. Zero dependencies. Pure stdlib.


The Problem

Every Python project ends up writing this:

PORT   = int(os.environ.get("PORT", 8080))
DEBUG  = os.environ.get("DEBUG", "false").lower() == "true"
DB_URL = os.environ["DATABASE_URL"] # KeyError with no helpful message

Manual casting. No validation. Cryptic error. Every. Single. Project.

The solution

from pureenv import env # .env file auto-loaded if it exists

PORT   = env("PORT",                default="8080") # no casting needed  
PORT   = env.int("PORT",            default=8080)   # or typed
DEBUG  = env.bool("DEBUG",          default=False)
DB_URL = env.str("DATABASE_URL",    required=True)

Typed. Validated. Clear errors when something is wrong.

Install

pip install pureenv

Usage

Create a .env file in your project root:

DATABASE_URL=postgres://localhost/mydb
DEBUG=true
PORT=8080

Then just import and use - no setup needed:

from pureenv import env

# strings - without casting (return str)
APP_NAME  = env("APP_NAME",     default="myapp")

# explicit str
DB_HOST = env.str("DB_HOST", default="localhost")

# numbers
PORT  = env.int("PORT",    default=8080)
RATIO = env.float("RATIO", default=0.5)

# booleans - accepts "true/false", "1/0", "yes/no", "y/n", "on/off"
DEBUG = env.bool("DEBUG", default=False)

# required - raises a clear error if missing
DB_URL = env.str("DATABASE_URL", required=True)

Why not environs or python-dotenv?

pureenv python-dotenv environs
Typed casting
Zero dependencies
Required validation
Loads .env file
Auto-loads .env

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

pureenv-0.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pureenv-0.2.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file pureenv-0.2.1.tar.gz.

File metadata

  • Download URL: pureenv-0.2.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pureenv-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f52729e3aaf8a38adfe3c152a0f55457b054be00cbb428f53d8bc0f5d692a192
MD5 58bf0dec125969e660c97e38f73aae25
BLAKE2b-256 367ed0be1e42326a4f1e835dbaf4258494c1c7d5e647c35272c8b5f53565bc89

See more details on using hashes here.

File details

Details for the file pureenv-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pureenv-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pureenv-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0cf285eb22ecdf7c53ec26084cdd5ad6e1f9d9463a8d256395e28aa937ce6b4
MD5 1792aaf3c8fb0dfc2b4d90cc41133d24
BLAKE2b-256 5dc53d97124c0c647119b5c0b1c657405379b0e0d9ebaf1a9451c466ffe10a22

See more details on using hashes here.

Supported by

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