AI-native runtime imports with automatic package resolution, installation, retry, lazy loading, and lightweight agent workflows.
Project description
nanoimports
nanoimports is an autonomous, AI-native import layer for Python. It detects missing imports,
resolves the import name to the correct pip package, installs the dependency, retries the import,
and caches the resolution locally.
from nanoimports import auto, smart_import
pd = smart_import("pandas")
cv2 = smart_import("cv2")
torch = smart_import("torch", lazy=True)
numpy = auto("numpy")
What Works In The MVP
smart_import()for import, install, retry, and local cache.auto()as a minimal ergonomic alias.- Built-in import-to-package resolution for common mismatches:
cv2 -> opencv-python,PIL -> pillow,yaml -> pyyaml,sklearn -> scikit-learn. - SQLite cache for package resolutions and install logs.
- Installer selection with
uv pip installpreferred andpython -m pip installfallback. dry_runmode.- Lazy import proxy with first-attribute loading.
- Lightweight security checks before installation.
- Repair suggestions for DLL/native extension errors, version conflicts, and missing system deps.
- Conservative
sys.meta_pathhook used bynanoimports run. - CLI for running scripts, resolving names, checking the environment, and managing cache.
Install
From a checkout:
python -m pip install -e .
For development:
python -m pip install -e ".[dev]"
pytest
API
from nanoimports import smart_import
cv2 = smart_import("cv2")
When cv2 is missing, nanoimports:
- catches
ModuleNotFoundError; - resolves
cv2toopencv-python; - records the resolution in SQLite;
- installs with
uv pip install opencv-pythonorpython -m pip install opencv-python; - invalidates import caches;
- retries
import cv2.
Use dry_run=True to inspect the planned install without changing the environment:
smart_import("cv2", dry_run=True)
Use install=False to get standard import behavior plus nanoimports diagnostics:
smart_import("pandas", install=False)
Use lazy=True for heavy dependencies:
torch = smart_import("torch", lazy=True)
# torch is imported when an attribute is first accessed
CLI
nanoimports run app.py
nanoimports doctor
nanoimports doctor --json
nanoimports resolve cv2
nanoimports cache list
nanoimports cache clear
nanoimports import cv2 --dry-run
nanoimports run app.py installs a conservative meta-path hook and then executes the script.
When Python cannot find a top-level module, the hook resolves and installs it before retrying.
Architecture
The package is intentionally small and modular:
nanoimports.agents.detection.ImportDetectionAgentnormalizesImportErrorandModuleNotFoundError.nanoimports.agents.resolution.PackageResolutionAgentresolves import names to pip package names using cache, known mappings, fuzzy matching, and an optional LLM resolver protocol.nanoimports.agents.environment.EnvironmentAgentdetects the active Python environment and runsuvorpip.nanoimports.agents.security.SecurityAgentblocks unsafe package-name syntax and warns about suspicious near-matches.nanoimports.agents.repair.RepairAgentsuggests fixes for common post-install import failures.nanoimports.runtime.lazy.LazyModuledefers expensive imports.nanoimports.runtime.hooks.NanoImportHooksupports autonomous imports while running scripts.nanoimports.cache.sqlite.ResolutionCachestores resolutions and install logs.
Cache
By default, cache data is stored at:
~/.cache/nanoimports/nanoimports.sqlite3
Override this with:
NANOIMPORTS_CACHE_DIR=/path/to/cache nanoimports resolve cv2
or with CLI/API cache_path.
Security Model
Runtime installation is powerful. nanoimports keeps the MVP deliberately conservative:
- package names must match a safe package-name pattern;
- known import aliases resolve through explicit mappings;
- suspicious near-matches produce warnings;
strict_security=Trueturns warnings into hard failures;- every install command is logged.
For production services, prefer pinned dependencies and use nanoimports in controlled workflows, developer tools, notebooks, prototypes, or self-healing automation where runtime installation is acceptable.
Stretch Goals
The public API intentionally leaves room for:
- semantic imports such as
auto(task="vector database"); - richer PyPI metadata validation;
- notebook integration;
- VS Code extension support;
- dependency graph visualization;
- autonomous repair mode;
- telemetry dashboards.
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 nanoimports-0.1.0.tar.gz.
File metadata
- Download URL: nanoimports-0.1.0.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac68b5cd240d6195de807824f5d57b6ee244930eef0d7d32b981ee033752dfb4
|
|
| MD5 |
bf5f1027d81f52612e61ca055b709c64
|
|
| BLAKE2b-256 |
384ff5da3b7d4811ac8258c14b983ea913dba7b6caca8406c3dcd1fadeee7d18
|
File details
Details for the file nanoimports-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nanoimports-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdb8f86f5f3f93cbf96bbef99d81f32dcbb620ec2465dd44f43bb3ce95bc34b5
|
|
| MD5 |
2878b3cffb0b06a3dd4235154d3366c1
|
|
| BLAKE2b-256 |
79a31a2e962a7ea98431499ca6a0bf5061800416be49384356afaafeae600c86
|