Skip to main content

Minimalist environment variable access: env.VAR or env('VAR', default=...)

Project description

simpenv

simpenv is a minimalist Python library for accessing environment variables. It lets you read variables as attributes or via function calls – no more repetitive os.getenv().

Features

  • Two ways to access: env.VAR or env("VAR")
  • Optional default values when a variable is missing
  • Automatically loads .env file from current directory (if exists)
  • Lightweight, zero external dependencies

Installation

pip install simpenv

Usage

Just import env – no need for from simpenv import env.

1. Import

import env

The env object is ready to use immediately.

2. Access environment variables

As an attribute

# Assume DATABASE_URL is set in the environment or .env file
db_url = env.DATABASE_URL

# Returns None if the variable does not exist
api_key = env.API_KEY

As a function call

db_url = env("DATABASE_URL")
api_key = env("API_KEY")

3. Provide a default value

Use the default parameter with the function form to avoid None values.

port = env("PORT", default=8080)
debug = env("DEBUG", default=False)

Note: The attribute style (env.VAR) does not support defaults – use the function style when you need a fallback value.

4. Using a .env file

Create a .env file in your project directory:

DATABASE_URL=postgresql://user:pass@localhost/db
PORT=3000
API_KEY=secret123

Then run your Python code:

import env

print(env.DATABASE_URL)        # postgresql://user:pass@localhost/db
print(env("PORT"))             # 3000
print(env("API_KEY"))          # secret123
print(env("NON_EXISTENT", default="no-value"))  # no-value

Environment variables set in your shell take precedence over those in .env.

5. Complete example

Set an environment variable in your shell:

export DATABASE_URL="postgresql://user:pass@localhost/db"
export PORT=3000

Then run your Python code:

import env

print(env.DATABASE_URL)        # postgresql://user:pass@localhost/db
print(env("PORT"))             # 3000
print(env("API_KEY"))          # None
print(env("API_KEY", default="no-key"))  # no-key

License

MIT

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

simpenv-1.0.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

simpenv-1.0.2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file simpenv-1.0.2.tar.gz.

File metadata

  • Download URL: simpenv-1.0.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for simpenv-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1393ec5fedcc2f71810b227b78336dcfdba745c6a3895cea5ad1ac64b32b21d7
MD5 b1ba67e52dde0043d817ed6b05dba032
BLAKE2b-256 2a4b172d6ec9601116d6706e35e75d27d1bd75ccf2f36576675bef6bdd40d16e

See more details on using hashes here.

File details

Details for the file simpenv-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: simpenv-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for simpenv-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 279622a1afa6e7162389b12236bd61728c450f82d75b292bc04eb964ae1b7d15
MD5 b0cd851f52fc4f61771fc48d1e9b4123
BLAKE2b-256 cd074f5ee6a51e1413c2413d9ae0fd6255ba2d18d70e0298d4330d31381fe5ea

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