Automatic Python environment reconstruction — runtime import tracing, snapshot, and restore.
Project description
envcore
pip freeze done right — only what your code actually uses.
pip freeze dumps your entire environment — often 200+ packages — most of which your project never touches. pipreqs scans source files but misses dynamic imports, conditional imports, and anything loaded at runtime.
Envcore hooks into Python's import system while your code actually runs, records only what gets imported, and writes a clean manifest. One command rebuilds that exact environment anywhere.
envcore trace train.py → env_manifest.json → envcore restore
No config files to maintain. No guesswork. Ship the manifest with your code.
Install
pip install envcore
Requires Python 3.9+.
Usage
Trace your script:
envcore trace train.py
Traced 3 packages:
numpy 1.26.4
pandas 2.1.4
torch 2.1.0
Manifest saved → env_manifest.json
Restore anywhere:
envcore restore
That's it. The manifest contains only what was actually imported — nothing more.
Why runtime tracing?
Static tools read your source files. They miss:
import torchinside anif cuda_available:block- imports inside functions, called only at runtime
- dynamic
importlib.import_module(...)calls - packages imported by your dependencies on your behalf
Envcore catches all of these because it watches what Python actually loads, not what it might load.
Note: Envcore traces one execution. If your code has branches that aren't hit during tracing (e.g. a
prod-only import), those won't be captured. Trace against a representative run.
Programmatic API
import envcore
envcore.start_tracking()
import numpy
import pandas
from sklearn.model_selection import train_test_split
envcore.stop_tracking()
envcore.snapshot("env_manifest.json")
Context manager:
from envcore import ImportTracer
with ImportTracer() as tracer:
import numpy
import pandas
print(tracer.module_names) # ['numpy', 'pandas']
Decorator:
from envcore import ImportTracer
tracer = ImportTracer()
@tracer
def train():
import torch
import wandb
train()
print(tracer.module_names) # ['torch', 'wandb']
Jupyter Notebooks
envcore notebook analysis.ipynb
Or inside a running notebook:
%load_ext envcore
%envcore start
import numpy, pandas
%envcore snapshot
How it works
1. TRACE builtins.__import__ → ImportTracer hook
Records module name, filters stdlib and pre-existing packages
2. RESOLVE import name → PyPI package + pinned version
"PIL" → Pillow 10.2.0
"cv2" → opencv-python 4.9.0
"sklearn" → scikit-learn 1.4.0
3. MANIFEST env_manifest.json
{ "numpy": "1.26.4", "torch": "2.1.0", ... }
4. RESTORE pip install numpy==1.26.4 torch==2.1.0 ...
Other commands
| Command | What it does |
|---|---|
envcore trace <script> |
Trace a script, save manifest |
envcore restore |
Install packages from manifest |
envcore show |
Print manifest contents |
envcore diff <a> <b> |
Compare two manifests |
envcore export -f <format> |
Export to requirements.txt, pyproject.toml, conda, docker, pipfile, setup.py |
envcore sync |
Diff manifest vs existing requirements.txt |
envcore doctor |
Check for missing, outdated, or orphaned packages |
envcore minimize |
Find the minimal top-level install set |
envcore lock |
Generate lockfile with SHA-256 hashes |
envcore audit |
Scan for vulnerabilities via OSV.dev |
envcore ci |
Exit 0/1 based on whether environment matches manifest |
Every command supports --help. Set NO_COLOR=1 to disable colour output.
Configuration
# pyproject.toml
[tool.envcore]
manifest = "env_manifest.json"
exclude = ["setuptools", "pip", "wheel"]
entry_points = ["src/main.py"]
auto_export = "requirements.txt"
Contributing
git clone https://github.com/JanBremec/envcore.git
cd envcore
pip install -e ".[dev]"
pytest tests/ -v
Issues and PRs welcome.
License
MIT — Jan Bremec
Project details
Release history Release notifications | RSS feed
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 envcore-0.1.1.tar.gz.
File metadata
- Download URL: envcore-0.1.1.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc5920878cf8ec138f591acc125fad1106507c94a84604584a95a28f94050479
|
|
| MD5 |
e2a7e9ab83d7aa2f2cd1d38d1bcc0e07
|
|
| BLAKE2b-256 |
8d8b28a74bad8770da3940151167a87e23c815f14efe533e778cbcb5e7c54a04
|
Provenance
The following attestation bundles were made for envcore-0.1.1.tar.gz:
Publisher:
ci.yml on JanBremec/envcore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
envcore-0.1.1.tar.gz -
Subject digest:
fc5920878cf8ec138f591acc125fad1106507c94a84604584a95a28f94050479 - Sigstore transparency entry: 1653673111
- Sigstore integration time:
-
Permalink:
JanBremec/envcore@d5a3e60f09d62d8b1aa3dba692ed2200ff64b470 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/JanBremec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@d5a3e60f09d62d8b1aa3dba692ed2200ff64b470 -
Trigger Event:
push
-
Statement type:
File details
Details for the file envcore-0.1.1-py3-none-any.whl.
File metadata
- Download URL: envcore-0.1.1-py3-none-any.whl
- Upload date:
- Size: 43.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2af9eeccaeadb6452c8d32488d96fe82e8ba69f0c02cfde53322d335c02c11f3
|
|
| MD5 |
1e9bb950ba3369212e6d2aa9ea9752b2
|
|
| BLAKE2b-256 |
06e68acf164e51b489fedb198c0eb1b58287f1b4b63c3ba289d23fd8a4282dce
|
Provenance
The following attestation bundles were made for envcore-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on JanBremec/envcore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
envcore-0.1.1-py3-none-any.whl -
Subject digest:
2af9eeccaeadb6452c8d32488d96fe82e8ba69f0c02cfde53322d335c02c11f3 - Sigstore transparency entry: 1653673703
- Sigstore integration time:
-
Permalink:
JanBremec/envcore@d5a3e60f09d62d8b1aa3dba692ed2200ff64b470 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/JanBremec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@d5a3e60f09d62d8b1aa3dba692ed2200ff64b470 -
Trigger Event:
push
-
Statement type: