Multi-version Python package manager and dependency isolation tool
Project description
🧶 EnvKnit
Multi-environment package manager for Python and Node.js.
EnvKnit provides a modern alternative to traditional virtual environments (venv). Instead of creating redundant environment folders for every project, EnvKnit uses a blazing-fast Rust CLI to resolve dependencies and stores all packages in a single global store.
With one envknit.yaml, you can cleanly define and switch between multiple, isolated environments (e.g., default, ml, frontend) without the overhead of heavy virtual environments.
✨ Key Features
- Multi-Environment Management: Define multiple environments in a single project. Switch seamlessly between a
defaultbackend env and anmlenv with different dependencies. - Global Package Store: Packages are installed exactly once in
~/.envknit/packages/and shared across all projects. Say goodbye to gigabytes of duplicated.venvfolders. - Unified Toolchain: Natively respects
python_versionandnode_versionconfigurations via integrations with tools likemise,fnm, andpyenv. - Rust-Powered CLI: Ultra-fast dependency resolution and deterministic
envknit.lock.yamlgeneration. - Transparent Execution: Run tools with
envknit run -- <command>to automatically inject the correct environment paths intoPYTHONPATHorPATH.
🚀 Quick Start
1. Define Environments
Create an envknit.yaml to define your project's environments.
envknit init
# Add to the default environment
envknit add "fastapi>=0.100"
# Add to a specialized 'ml' environment
envknit add "torch>=2.0" --env ml
envknit add "numpy>=1.24,<2.0" --env ml
2. Lock and Install
Resolve dependencies and install them to the global store.
envknit lock
envknit install
3. Run Your Code
Execute your scripts in the context of a specific environment.
# Runs with 'default' environment packages injected into PYTHONPATH
envknit run -- python app.py
# Runs tests skipping dev dependencies
envknit run --no-dev -- python -m pytest
# Runs a training script using the isolated 'ml' environment
envknit run --env ml -- python train.py
⚠️ Advanced Feature: In-Process Isolation (Experimental)
EXPERIMENTAL: EnvKnit intentionally bypasses Python's "one module per process" singleton rule. While powerful for API migrations, it breaks traditional type checking (
isinstance) across versions. Use with caution.
Beyond standard environment management, EnvKnit provides three strategies for in-process isolation:
Gen 1 — Soft Isolation (use())
Dynamically routes imports via ContextVars. Fast, but shares global interpreter state.
import envknit
with envknit.use("requests", "2.28.2"):
import requests
print(requests.__version__) # 2.28.2
(For C-extension packages like numpy, use envknit.worker() to isolate them in subprocesses.)
Gen 2 — Hard Isolation (SubInterpreterEnv, Python 3.12+)
Spawns a true C-API sub-interpreter (PEP 684) with its own independent sys.modules, sys.path, and GIL. Host site-packages are never visible inside the sub-interpreter.
from envknit.isolation import SubInterpreterEnv
with SubInterpreterEnv("ml") as interp:
interp.configure_from_lock("envknit.lock.yaml", env_name="ml")
result = interp.eval_json("""
import some_ml_lib
result = {"version": some_ml_lib.__version__, "status": "ok"}
""")
print(result) # {"version": "...", "status": "ok"}
See the Gen 2 Hard Isolation Guide for full details on DTO patterns, C-extension fallback, and serialization constraints.
Thread Context Propagation (ContextThread, ContextExecutor)
By default, threading.Thread does not inherit ContextVar state. Use opt-in wrappers to propagate the active version context to background threads:
from envknit.isolation import ContextThread, ContextExecutor
with envknit.use("requests", "2.28.2"):
# ContextThread snapshots context at __init__ time
t = ContextThread(target=worker_fn)
t.start()
# ContextExecutor snapshots context at submit() time
with ContextExecutor(max_workers=4) as pool:
future = pool.submit(worker_fn)
📦 Installation
EnvKnit consists of two components: the Rust CLI (for management) and the Python library (for runtime hooks). You need both.
Step 1: Install the CLI Binary
Required for envknit init, lock, install, and run.
# Linux
curl -L https://github.com/wgsim/EnvKnit/releases/latest/download/envknit-linux-amd64 -o envknit
chmod +x envknit && sudo mv envknit /usr/local/bin/
# macOS (Apple Silicon)
curl -L https://github.com/wgsim/EnvKnit/releases/latest/download/envknit-macos-arm64 -o envknit
chmod +x envknit && sudo mv envknit /usr/local/bin/
(For Windows and other platforms, see the Releases page.)
Step 2: Install the Python Library
Required for the envknit.use() and envknit.worker() APIs.
pip install envknit # Requires Python 3.10+
📚 Documentation
Dive deeper into how EnvKnit works and how to integrate it into your workflow.
Guides
| Document | Description |
|---|---|
| 🚀 Getting Started | Installation, first run, and a 20-minute tutorial. |
| 🔄 Migration Guide | How to move from requirements.txt, Poetry, or venv to EnvKnit. |
| 🧠 Architecture & Concepts | How the global store, PYTHONPATH, and import hook work. |
| 💻 CLI Scripts | How to run pytest, black, mypy, etc., with envknit run. |
| 🐍 Python Version | Using python_version with mise/pyenv. |
| 🟢 Node Version | Using node_version with fnm/nvm/mise. |
| 🔌 Python API | Deep dive into use(), worker(), and configure_from_lock(). |
| 🛡️ Gen 2 Hard Isolation | Using Python 3.12+ Sub-interpreters for strict global state isolation. |
| 🌍 Environments | Managing multiple environments (default, ml, dev). |
| ⚙️ CI Integration | Setting up EnvKnit in GitHub Actions. |
| 🛠️ Troubleshooting & FAQ | Solutions for common errors, C-extensions, and CLI path issues. |
Reference
| Document | Description |
|---|---|
| ⌨️ CLI Reference | Complete CLI command reference. |
| 📝 Config Schema | envknit.yaml and global config fields. |
| 🔒 Lock Schema | envknit.lock.yaml structure. |
🤝 Contributing
We welcome contributions! EnvKnit is built with Rust and Python.
git clone https://github.com/wgsim/EnvKnit.git
cd EnvKnit
# Test the Rust CLI
cargo test
# Test the Python runtime library
pip install -e ".[dev]"
python -m pytest
📄 License
EnvKnit is distributed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file envknit-0.1.2.tar.gz.
File metadata
- Download URL: envknit-0.1.2.tar.gz
- Upload date:
- Size: 274.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
498c7d06faf15198b421af56292ffd7890e548ec5a45683f314fac9914f82f60
|
|
| MD5 |
d8ae4293491621ea667f309599b40750
|
|
| BLAKE2b-256 |
c8d83125b399b3f7c342e52d6ff22bd726b2e920ddd40797cfb8d519ec5b0a97
|
File details
Details for the file envknit-0.1.2-py3-none-any.whl.
File metadata
- Download URL: envknit-0.1.2-py3-none-any.whl
- Upload date:
- Size: 99.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fe476c45e06f775e80d1b44517a897ec2e417a82a38960d5b1ee61b7d4404d8
|
|
| MD5 |
0c64a8535f5c1c01b45f9d2b7fbec90a
|
|
| BLAKE2b-256 |
29d8d50be96411f188640aabf47dad30c56d071a3c7df0264b7301c0c8a51af4
|