_ _
_____ _| |_ _ __ __ _ ___| |_ _ __ ___ __ _ ___
/ _ \ \/ / __| '__/ _` |/ __| __| '__/ _ \/ _` / __|
| __/> <| |_| | | (_| | (__| |_| | | __/ (_| \__ \
\___/_/\_\\__|_| \__,_|\___|\__|_| \___|\__, |___/
|_|
Description
A lightweight and intelligent tool designed to automatically analyze your Python source code, detect imported libraries, and generate accurate requirements.txt files without manual configuration.
Features
-
Automated Extraction: Recursively scans your Python files to identify all active dependencies.
-
Standard Library Filtering: Smartly differentiates between built-in Python modules and third-party packages, keeping your requirements clean.
-
File Generation: Automatically formats and writes a neatly sorted requirements.txt file ready for deployment.
-
Dual Interface: Seamlessly use it as a command-line tool or import it as a module directly into your Python automation scripts.
-
Zero Configuration: Just point it at a directory and it instantly handles the rest.
Installation
You can install extractreqs directly from PyPI using standard package managers:
pip install extractreqs
### Usage Examples
Basic Python Usage
- extractreq(src_dir, write)
Scans the specified directory, extracts the necessary third-party modules, and optionally generates the file.
import extractreqs
# Analyze source code and generate requirements.txt automatically
try:
reqs = extractreqs.extractreq(src_dir="/path/to/your/source", write=True)
print("Successfully extracted requirements:")
for req in reqs:
print(f"- {req}")
except Exception as e:
print(f"Failed to extract requirements: {e}")
CLI Usage
extractreqs . -o requirements.txt
Under the hood, this will:
-
Scan the current directory (.) for all .py files.
-
Parse the Abstract Syntax Tree (AST) to find import and from ... import statements.
-
Filter out Python's standard library modules.
-
Write the final list of external dependencies into requirements.txt.
Complete Workflow Example
If you are building a deployment pipeline, you can dynamically generate your requirements before packaging:
from pathlib import Path
import extractreqs
def prepare_deployment():
project_root = Path.cwd()
print(f"Scanning {project_root} for dependencies...")
# 1. Extract requirements and create the file
dependencies = extractreqs.extractreq(src_dir=str(project_root), write=True)
# 2. Verify results
if dependencies:
print(f"Successfully generated requirements.txt with {len(dependencies)} packages.")
else:
print("No external dependencies found. Project uses only standard libraries.")
# Execute the workflow
prepare_deployment()
Development
To set up for local development:
# Clone your fork
git clone git@github.com:your_username/extractreqs.git
cd extractreqs
# Install dependencies
uv sync
# Create a branch for development
git checkout -b feature/new-awesome-feature
Author
extractreqs was created in 2026 by Hasan Ali Özkan.
Credits
Built with Cookiecutter and the audreyfeldroy/cookiecutter-pypackage project template.
Release files for extractreqs 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| extractreqs-0.1.2.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| extractreqs-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / extractreqs-0.1.2.tar.gz
| Download URL | extractreqs-0.1.2.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
148acd9e9acb492e9668559f504015bf66623986ec493214fc25d88bce0e2702
|
|
BLAKE2b-256 checksum How to use checksums |
551ba9f42e82f14601157c8682bf11810fdc7f53a65a835268c65970939d6fd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / extractreqs-0.1.2-py3-none-any.whl
| Download URL | extractreqs-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e25254e1e4fbf178ad3158a13cc61c04f01618b34fa8daee9806b35a3e3a8202
|
|
BLAKE2b-256 checksum How to use checksums |
34aedeff51763f8c954d7412f8ce1157b758c94044ffdc7452e53530fcfff192
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|