_ _
_____ _| |_ _ __ __ _ ___| |_ _ __ ___ __ _ ___
/ _ \ \/ / __| '__/ _` |/ __| __| '__/ _ \/ _` / __|
| __/> <| |_| | | (_| | (__| |_| | | __/ (_| \__ \
\___/_/\_\\__|_| \__,_|\___|\__|_| \___|\__, |___/
|_|
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.
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.
You can install extractreqs directly from PyPI using standard package managers:
pip install extractreqs
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}")
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.
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()
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
extractreqs was created in 2026 by Hasan Ali Özkan.
Built with Cookiecutter and the audreyfeldroy/cookiecutter-pypackage project template.