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.1.tar.gz (3.4 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.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simpenv-1.0.1.tar.gz
  • Upload date:
  • Size: 3.4 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.1.tar.gz
Algorithm Hash digest
SHA256 dd40d788339009f006f2c679e2674e6ae4f1d58b878c373adf47a14259a1ad20
MD5 267b1866216068bc643738127b354ff0
BLAKE2b-256 2d90364265122fdecc64b5d9d80352cf41ccae61d243df739f89a768b9a0ee9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simpenv-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7c8f4e72df85904cdcb002d9c54a0bd54bea117ad6faab2438466771725f43b
MD5 9f7cbdb75e3bd2ea85b919d61bab5248
BLAKE2b-256 8f0f8950105ed498ca48d6c7e2cb2cd3bfd8692a34c28ca3a2739a77b88012ed

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