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)

# grouping related env variables
with env.prefix("DB_"):
    DB_HOST = env("HOST", default="localhost") # reads DB_HOST
    DB_PORT = env("PORT", default="5432")      # reads DB_PORT
    DB_NAME = env("NAME", default="mydb")      # reads DB_NAME

Why not environs or python-dotenv?

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

Auto-loads means no setup needed — just from pureenv import env and your .env is loaded automatically.

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.4.0.tar.gz (6.2 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.4.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pureenv-0.4.0.tar.gz
Algorithm Hash digest
SHA256 717035b0eb11f5aad0a41efa860e4bf44caf815cb93f6110b39f74b54b1deb05
MD5 196ec843968eda21474853065f15322b
BLAKE2b-256 e57a6f0bf0802d7f27da1318884fa6d26f09aee4ad1341af1229cd6fe7ec7c1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pureenv-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70b977bc4e8444a55a6ac8c4c0f18cbbf672538c75e9186189e3f3370b393d66
MD5 736e989f39c4d49f8221c776afdf2873
BLAKE2b-256 1441e72ef98c74595f5611cd573bc08b2a3e758ee8a11f8551732313a250e746

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