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.3.0.tar.gz (5.4 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.3.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pureenv-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5596da0c75e370d665730d16448b0724f08e75ed357b81476f375ae3fbe6feed
MD5 9366b241e8ccde7a0758999919a684b0
BLAKE2b-256 8af285742193240d5314fd94ff2e67236cc05ac103f52af8b6dea4bebe05ee18

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pureenv-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e30e9f31a94440859ef260c62f1618ef627b07b5908fb5c5186f75e658dd3a71
MD5 1f916b375bdcdc401949e599c9afe05e
BLAKE2b-256 014f2afa4163ec60b5042ae8de16dd9ec871b20237ca8aec2c2fa2efd66b60c3

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