Skip to main content

PyPI version License - MIT 3-Clause PyPI Downloads Visitors

           _                  _                      
  _____  _| |_ _ __ __ _  ___| |_ _ __ ___  __ _ ___ 
 / _ \ \/ / __| '__/ _` |/ __| __| '__/ _ \/ _` / __|
|  __/>  <| |_| | | (_| | (__| |_| | |  __/ (_| \__ \
 \___/_/\_\\__|_|  \__,_|\___|\__|_|  \___|\__, |___/
                                              |_|    

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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for extractreqs 0.1.3
File Size Uploaded
extractreqs-0.1.3.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for extractreqs 0.1.3
File Interpreter ABI Platform
extractreqs-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / extractreqs-0.1.3.tar.gz

Download URL extractreqs-0.1.3.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
91eb44975de21b7b3acd1b536bb366c2bb2b19bec7d65b9d2ac37160a5d262f1
BLAKE2b-256 checksum
How to use checksums
b0c7c20ffeaccf36c6ad83ced96bc3573076d645507d56a1057248e34899b881
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.3-py3-none-any.whl

Download URL extractreqs-0.1.3-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b49885261f1af5d8640140e476f2cdd74bbbf59f120dcaf37e98c0f47508a505
BLAKE2b-256 checksum
How to use checksums
08557eaa629c01e6f809f22cfcdde76493bb4edc5c49fbaf0c75d9815f3d6271
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 history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page