LLM-backed synthetic compatibility modules generated on import.
Project description
hallucipip
hallucipip is an experimental Python package that synthesizes missing modules with an LLM at import time, caches the generated source locally, and then loads that cached file as a normal Python module.
This is still a joke-adjacent project, but the underlying mechanism is real and useful enough to describe plainly: it is a lightweight import hook for rapid prototyping, compatibility experiments, demos, and intentionally fake dependencies.
What it does
- Intercepts imports for modules that are not installed locally.
- Generates a synthetic implementation by calling an LLM through the OpenAI-compatible API.
- Writes the generated module into a local cache directory.
- Imports the cached file through Python's normal module loader on subsequent runs.
In other words, hallucipip treats a missing dependency as a code-generation request instead of an installation failure.
Why this exists
There are two plausible use cases:
- Prototype-first development where you want a fake module quickly and you are comfortable with rough edges.
- Developer tooling experiments around import hooks, synthetic packages, and LLM-generated compatibility shims.
It is not a substitute for real package management, reproducible builds, or audited dependencies.
How it works
The core logic is intentionally simple:
- Importing
hallucipipinstalls aMetaPathFinderintosys.meta_path. - When Python tries to import a top-level module that is not already installed or part of the standard library, the finder takes over.
- The finder computes a request signature from the module name, target model, version hint, and generation prompt.
- If a matching cached file already exists in
~/.hallucipip/cache(or your configured cache directory), that file is loaded immediately. - Otherwise
hallucipipprompts an LLM to generate a single-file Python implementation with no third-party dependencies. - The generated file is written to the cache and imported through
importlib.util.spec_from_file_location.
That design keeps the first implementation narrow and inspectable:
- No build backend tricks.
- No binary artifacts.
- No hidden daemon or service process.
- Just import interception, generation, caching, and normal Python module loading.
Installation
uv pip install hallucipip
Or with pip:
pip install hallucipip
Quickstart
import hallucipip
hallucipip.configure(
model="anthropic/claude-3.7-sonnet",
api_key="...",
hallucination_intensity=4,
debug=True,
)
import fake_math_lib
print(fake_math_lib.__version__)
print(fake_math_lib.add(2, 3))
You can also provide configuration through environment variables:
HALLUCIPIP_MODELHALLUCIPIP_BASE_URLHALLUCIPIP_TEMPERATUREHALLUCIPIP_MAX_TOKENSHALLUCIPIP_INTENSITYHALLUCIPIP_CACHE_DIRHALLUCIPIP_DEBUGOPENROUTER_API_KEYANTHROPIC_API_KEYOPENAI_API_KEY
Version hints
If you want the generator to aim at a particular public API shape, add an inline import comment:
import imaginary_numpy # hallucipip: imaginary_numpy>=2.0,<3
The hint becomes part of the generation request and the cache signature, so different compatibility targets do not overwrite each other.
CLI
hallucipip config
hallucipip cache list
hallucipip cache clear
Use --debug to enable structured logs on stderr.
Operational notes
- Cached modules are plain
.pyfiles, so you can inspect exactly what was generated. - The cache key is derived from the actual generation request, not just the module name, which makes cache reuse more predictable.
- The package only handles missing top-level imports in this first release. Deep package emulation is intentionally out of scope for now.
Limitations
- Generated modules are not trustworthy by default.
- Behavior may drift across models or prompt changes.
- Non-trivial libraries with large extension surfaces will only get partial compatibility.
- This project has not been designed for security-sensitive or production-critical environments.
Development
uv sync --extra dev
uv run pytest
uv run python -m build
Publishing
The repository is structured for a standard PyPI release:
pyproject.tomluses Hatchling.- The package follows the
src/layout. - The README is PyPI-friendly.
- Wheel and sdist builds can be produced with
python -m build.
When you are ready to publish:
uv run python -m build
uv run twine upload dist/*
License
MIT
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 hallucipip-0.1.0.tar.gz.
File metadata
- Download URL: hallucipip-0.1.0.tar.gz
- Upload date:
- Size: 3.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
670ea05fdd9397bed1d60579d67114d87d687f3f76abcc5e516921e7745f3734
|
|
| MD5 |
efd98f2943b22bc13463108b2fc80ae4
|
|
| BLAKE2b-256 |
344ac74f2f9ed429bc8e8cdc92ec8664c78e15a1f940305eed16895f633b8a75
|
File details
Details for the file hallucipip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hallucipip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39de120815cb220b110cfe391baf1c45b1ca16e3cbcd3241c8b0484e37a8da9f
|
|
| MD5 |
b5486c05476801f8c4338db8f39fc605
|
|
| BLAKE2b-256 |
ac50a8b559f305d562d5679ae7c2e95a4fb82544d0ef13fde52aae28457bd5d5
|