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.1.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.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pureenv-0.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2a5273d353f75605f72a08ffcb01eaaf4a846bf63bfc4f0edebbc45a5492cec6
MD5 ca2f6f249670a5f1b5444a0fda030fb0
BLAKE2b-256 f6bdd4e086afc46b16681146ccd0262e8a8356b0bd860e0935d211c025508c01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pureenv-0.3.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a75c0434fe0925125e093c7ba9cde1d00472dbb17042b9c51548f2b0e1c4b3a4
MD5 6bfd792e1f508916ef1e8d7bbb75f8d0
BLAKE2b-256 2a9ed521896e1ce90dc3154b9289a934c4298de15e1e171a99af4979e4a10214

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