Skip to main content

Auto-load .env files and run commands or read envs in Python.

Project description

Envyte

Tiny helper to auto-load environment variables from .env files and run your commands or Python scripts with those variables available. It also exposes a small Python API for reading env values safely.

Features

  • Auto-loads .env files from the current working directory before running your command/script
  • Simple CLI wrapper: run any command or directly run a Python file
  • Remembers the last Python script you ran in each project
  • Small Python helpers: get, getBool, getInt, getString

Installation

Install from PyPI (recommended):

pip install envyte

This installs Envyte and its dependency python-dotenv.

If you’re developing locally from this repository:

# from the repo root
python -m pip install -e .
python -m pip install python-dotenv

How it works (at a glance)

  • Envyte looks for .env files in your current working directory (where you invoke the CLI) and loads them before executing your command.
  • Files are loaded in this sequence: .env.local, then .env.dev, then .env.prod, then .env. Because variables loaded later override earlier ones, keys in .env win if duplicated.
  • When you call Envyte as a CLI without arguments, it tries to detect a Python entry file to run (see CLI section).
  • Envyte stores a per-project “last run” Python script at the path below so it can auto-run the same file next time:
    • Windows example: C:\\Users\\Contemelia\\.envyte.json

Note: Environment files are resolved in the current working directory only.

CLI usage

Basic form:

envyte [command and args]

Examples:

# Run a Python script explicitly
envyte python .\main.py --port 8080

# Run any arbitrary command (env is loaded first)
envyte uvicorn app:app --reload

# With no arguments: auto-detect a Python entry file
# - If exactly one *.py file exists in CWD, run it
# - If multiple, Envyte tries last run from C:\Users\Contemelia\.envyte.json
# - Otherwise it looks for main.py, app.py, server.py in that order
envyte

Alternative invocation (if you prefer module syntax):

python -m envyte [command and args]

What gets loaded:

  • In your project folder, create any of these files: .env, .env.prod, .env.dev, .env.local.
  • Define variables in standard KEY=VALUE lines.

Example .env:

PORT=8000
DEBUG=true
SECRET_KEY=dev-secret

Example .env.local:

DEBUG=false
SECRET_KEY=local-override

Then run your script with Envyte so your app gets those values:

envyte python .\main.py

Last-run history

Envyte writes and reads a simple JSON file to remember the last Python script used per project (directory):

  • Windows example path: C:\\Users\\Contemelia\\.envyte.json

This lets envyte (with no args) re-run the same entrypoint next time in the same folder.

Python API usage

Importing envyte will automatically load environment variables from .env files in your current working directory.

from envyte import get, getBool, getInt, getString

# .env is already auto-loaded on import

host = get("HOST", "127.0.0.1")
port = getInt("PORT", 8000)
debug = getBool("DEBUG", False)
secret = getString("SECRET_KEY", "")

print(host, port, debug, secret)

Available helpers:

  • get(key, default=None) -> Any
  • getBool(key, default=False) -> bool (truthy strings: "1", "true", "yes", "y", "on")
  • getInt(key, default=0) -> int (safe fallback to default on parse errors)
  • getString(key, default="") -> str

If you need manual control, you can import and call the loader directly before reading values:

from envyte.core import autoLoadEnvironmentVariables
from envyte import get

autoLoadEnvironmentVariables()
token = get("API_TOKEN")

Environment file priority

Load order in the current implementation (last wins on duplicates):

  1. .env.local
  2. .env.dev
  3. .env.prod
  4. .env (highest precedence because it loads last)

Note: The docstring in envyte/core.py references an intended priority of .env.local > .env.dev > .env.prod > .env (where earlier files would win). Given the loader uses override=True and the order above, variables in .env currently override the others. Adjust the load order if you prefer different precedence.

Tips and troubleshooting

  • Envyte loads from the current working directory. Run the CLI from your project folder where your .env files live.
  • If envyte (no args) says it cannot find an entrypoint, specify your script explicitly: envyte python .\main.py.
  • Ensure python-dotenv is installed in the same environment as your app.

License

See LICENSE in this repository.

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

envyte-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

envyte-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file envyte-0.1.0.tar.gz.

File metadata

  • Download URL: envyte-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for envyte-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1c1d71f0d4f753a504be0ddf13c1afa24194ff3f28e9e816050bdb2bb794425f
MD5 48a99f2d2a689e078e3f2a45eeceec09
BLAKE2b-256 f253abeb7dbcd2dd70e5d535ea248bf01510e5b85b162a49d426b76f1ada0b23

See more details on using hashes here.

File details

Details for the file envyte-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: envyte-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for envyte-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecda2d72515ceb05164abc1aaf2523d28e7ccdf2b91528e40ab42c4760557460
MD5 511bf6f80044308d3727fa0e96bf6824
BLAKE2b-256 e3d3267a0d198151089981ade46f26b02a9cb8d37ce8c16f8ea4b71c53fc0aed

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