Dynamic requirements loader for Python projects.
Project description
PYMPORTER
Dynamic Requirements Loader (Pure Python!)
##Description
This is a straightforward module that allows you to automatically install and import a project's dependencies from a text file, using an enriched syntax.
The general workflow is simple:
- Read the custom requirements file.
- Install the packages using pip (if requested).
- Dynamically import the modules and inject them into your script.
Everything happens at runtime, keeping your workspace flexible.
Installation
pip install pyimporter
(Or directly from GitHub for the latest version):
pip install git+https://github.com/AnderSantos113/pyimporter.git@v1.0.0
Basic Usage
Install + import everything directly into your scope: requirements("libs.txt")
Only import (assumes they are already installed): importer("libs.txt")
Only install (does not inject variables into your code): installer("libs.txt")
Requirements File Format
The syntax is designed to be flexible on a single line. The general structure is:
[import expression] [version] [: pip install name or url]
Valid Examples:
Simple imports
numpy pandas >= 2.0.0
Aliases and specific objects
import numpy as np numpy as np <= 1.21.0 from urllib import request as req
Different pip names / Custom URLs (See Special Cases below)
import bs4 : beautifulsoup4 pyimporter as pimp : git+https://github.com/AnderSantos113/pyimporter.git
Version Operators
== equal to
>= greater than or equal to <= less than or equal to />greater than < less than
Special Cases (The ":" Operator)
Sometimes the name you use to import a package in Python is not the same name you use to install it via pip.
For example: pip install beautifulsoup4 -> import bs4 pip install PyYAML -> import yaml
For these cases, you can use the : separator to specify the pip install name. The left side is what gets imported, and the right side is what gets installed:
import bs4 : beautifulsoup4 import yaml : pyyaml import cv2 : opencv-python
You can also use this to install directly from a GitHub repository: my_module : git+https://github.com/user/repo.git
Main Functions
requirements(file_path, force_reinstall=False, upgrade=False, show_output=True)
- Installs missing dependencies and imports them into your global scope.
- The most complete mode.
importer(file_path)
- Purely imports the packages into your scope.
- Does not attempt to install anything using pip.
installer(file_path, force_reinstall=False, upgrade=False, show_output=True)
- Only runs the pip installation process.
- Does not import or inject variables.
Design Notes
- 100% standard Python (no third-party dependencies).
- Uses importlib, subprocess, and warnings.
- Captures the caller's scope using sys._getframe() for variable injection.
Limitations
- Does not support complex PEP 440 versioning (like rc, dev, post releases).
- Pip is executed sequentially per package, not batched.
- Does not resolve complex dependency trees beforehand.
Warnings
- Because modules are injected directly into globals(), an alias might overwrite an existing variable in your code.
- It is recommended to use clear aliases to avoid namespace collisions.
Ideal Use Cases
- Self-contained scripts.
- Reproducible Jupyter Notebooks.
- Small to medium projects without a formal virtual environment.
- Quick prototyping and educational environments.
Author
Project developed by Ander Santos.
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 pymporter-1.0.0.tar.gz.
File metadata
- Download URL: pymporter-1.0.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3914f600f0118be92d64ff1b5620dc52bc00f9208452a889454c99f769d3537a
|
|
| MD5 |
76b93731cd265d7cac4a2f55ca63dd37
|
|
| BLAKE2b-256 |
71c2f33e5187bbda59401d9e7d60859e3242bc65d1ed9e9806be482fb395f8fa
|
File details
Details for the file pymporter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pymporter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a071b975852b7287b9bd4e12157ec51d2c91c6ff998ea7017e21f7f87204a84
|
|
| MD5 |
ebb7c76f2169750ddfa658536eba93e9
|
|
| BLAKE2b-256 |
c0bd85ee70af0c99eb0ff10079beb231c2db83d2080787289efc01538c6ea9a0
|