Python requirements.txt Generator

Build a Python requirements.txt from presets for Django, FastAPI, Flask, data science, ML and LLM stacks. Set ==, ~= or >= pinning, then copy or download.

Advertisement

Python requirements.txt Generator

This generator builds a requirements.txt file from a searchable catalogue of common Python packages, with the version pinning operator you choose applied consistently across every line. Pick a stack preset, add or remove packages, set ==, ~=, or >= per package, then copy the file to your clipboard or download it straight into your project. Everything runs in the browser — no account, no upload, no package index calls.

It is aimed at the moment when you start a project, not the moment you finish one. On a fresh Django service, a FastAPI microservice, a notebook-driven analysis, or an LLM app, the first requirements.txt is nearly always the same handful of packages plus whatever the framework needs to run in production — and it is easy to forget gunicorn or python-dotenv until deployment fails. Presets encode those lists so you start from a working baseline instead of a blank file.

What the Generator Includes

Eight quick-start presets cover the stacks that account for most new Python projects:

  • Django Web App — django, psycopg2-binary, python-dotenv, gunicorn, whitenoise, django-cors-headers, djangorestframework
  • FastAPI Microservice — fastapi, uvicorn, pydantic, httpx, python-dotenv, sqlalchemy, alembic
  • Flask API — flask, flask-cors, flask-sqlalchemy, python-dotenv, gunicorn, marshmallow
  • Data Science — numpy, pandas, matplotlib, seaborn, scikit-learn, jupyter, scipy
  • Machine Learning — torch, transformers, numpy, pandas, scikit-learn, tensorboard, tqdm
  • LLM Application — openai, anthropic, langchain, tiktoken, python-dotenv, pydantic, httpx
  • Testing Suite — pytest, pytest-cov, pytest-asyncio, coverage, faker, httpx
  • CLI Tool — typer, rich, click, python-dotenv, pyyaml, requests

Behind the presets sits a searchable catalogue of around fifty popular packages grouped by category — Web Framework, Data Science, AI/ML, Database, HTTP, Testing, CLI, Cloud, Utilities, and Security — each carrying a suggested version and a one-line description. Anything not in the catalogue can be added by hand with the custom name and version fields, so a private or niche dependency is one keystroke away.

Output options let you set the default pinning operator, include or strip the descriptive comments, sort alphabetically, and group the file into commented category blocks. The generated file is written to a live preview pane with a copy button and a download button.

How to Use It

  1. Start from a preset. Click the closest match to your project. The package list loads instantly and replaces whatever was there.
  2. Adjust the list. Search the catalogue and click to add; click the bin icon to remove. Add anything unusual with the custom package field.
  3. Set pinning. Choose a default operator in Output Options, then override individual packages in the selected list where a different rule makes sense.
  4. Tune the output. Decide whether comments help or clutter, whether to sort alphabetically, and whether to group by category.
  5. Copy or download. Download writes a file named requirements.txt ready to drop at your project root.

Version Pinning: Which Operator to Use

The operator you pick decides whether your build is reproducible or merely plausible, and the four options behave very differently.

==2.31 is an exact pin. Only that version satisfies it. This is what you want for anything you deploy: the environment that passes CI is bit-for-bit the environment that runs in production. The cost is that security updates never arrive on their own; you have to bump the file deliberately.

~=2.31 is the compatible release operator from PEP 440. It is equivalent to >= 2.31, == 2.* — it accepts later patch and minor releases within the same major series but refuses a major bump. Written with three components, ~=2.31.4 means >= 2.31.4, == 2.31.*, so only the patch digit is free to move. It is the sensible default for a library, where over-pinning forces version conflicts on everyone who depends on you.

>=1.26 is a floor. It states the oldest version whose API you use and permits anything newer, including a major release that removes the function you called. Useful in libraries alongside an explicit upper bound; risky on its own.

No pin at all means whatever the index serves on the day the build runs. That is fine for a throwaway script and unacceptable anywhere a build has to be repeatable.

A worked example. With the compatible-release default, the FastAPI preset renders as:

# Requirements generated by InventiveHQ Requirements Generator
# Generated on 2026-08-12

fastapi~=0.109 # Modern async web framework uvicorn pydantic~=2.6 # Data validation using Python type hints httpx~=0.26 # Async-capable HTTP client python-dotenv~=1.0 # Read key-value pairs from .env sqlalchemy~=2.0 # SQL toolkit and ORM alembic

Note that packages carrying no catalogue version emit a bare name — the operator is only appended when a version is present. Switch the default to exact and every ~= becomes ==; untick comments and the trailing # … text disappears.

What This File Is and Is Not

A requirements.txt generated here is a declaration of intent: the direct dependencies your code imports, at the versions you chose. It is not a lock file. Installing it resolves each transitive dependency freshly, so two installs a month apart can produce different sub-dependency versions even when your file has not changed. For genuinely reproducible builds, install into a clean virtual environment and then capture the full resolved tree:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip freeze > requirements.lock.txt

Keep both files, and make sure .venv/ is excluded from version control — the gitignore generator has a Python template that covers it along with __pycache__ and build artefacts. The hand-maintained requirements file says what you meant; the frozen one says what you got. Tools such as pip-tools, Poetry, and uv formalise exactly this split, and the file this generator produces is a valid input to all of them.

A related habit worth adopting: split development-only tooling into a separate file. Test runners, linters, and formatters have no business in a production image. Generate the Testing Suite preset, save it as requirements-dev.txt, and install it only in CI and on developer machines — the Dockerfile generator produces a Python image that installs only the production file.

Frequently Asked Questions

Does the tool look up the latest version from PyPI?

No. It runs entirely offline against a built-in catalogue of packages with sensible versions recorded at the time of writing. Treat those numbers as a starting point and confirm against PyPI before shipping — particularly for fast-moving AI and web packages.

What is the difference between ~= and >=?

~=2.6 allows newer releases within the same major version but blocks a major bump. >=2.6 allows anything newer including a breaking major release. Use ~= when you want updates without surprises, >= only when you also add an upper bound.

Should I pin exact versions?

For applications and anything you deploy, yes — exact pins make builds reproducible. For libraries other people install alongside their own dependencies, prefer ~=, because over-tight pins in a library cause unresolvable conflicts downstream.

Can I add a package that is not in the list?

Yes. Use the Add Custom Package field at the bottom of the catalogue panel: type the distribution name, optionally a version, and it is added with your current default pinning applied.

Does it support extras like uvicorn[standard]?

The output format renders extras in square brackets after the package name when an extras value is present on the entry. If you need them and they are not shown, add the full string as a custom package name.

Does it handle hashes or platform markers?

No. --hash entries and environment markers such as ; sys_platform == "win32" are not generated. Add them by hand after downloading, or generate hashes with pip-tools if your supply-chain policy requires them.

Where should the file live?

At the project root, committed to version control, next to your README. Keeping development tooling in a separate requirements-dev.txt keeps production images smaller and their attack surface narrower.

Is my package list sent anywhere?

No. Selection, formatting, and file generation all happen in your browser. Nothing is uploaded and nothing is stored. If you also need to pin front-end assets, our SRI hash generator produces subresource integrity hashes for the scripts your Python app serves.

What Is requirements.txt

requirements.txt is the standard dependency specification file for Python projects. It lists the Python packages required to run the project, optionally with version constraints, enabling anyone to recreate the exact environment using pip install -r requirements.txt. This file is the Python ecosystem's equivalent of package.json (Node.js) or Gemfile (Ruby).

This tool generates properly formatted requirements.txt files with common packages for various Python project types, including version pinning best practices and dependency grouping.

Dependency Specification Syntax

SyntaxMeaningExample
packageLatest versionrequests
package==1.2.3Exact versionrequests==2.31.0
package>=1.2.0Minimum versionrequests>=2.28.0
package>=1.2,<2.0Version rangerequests>=2.28.0,<3.0.0
package~=1.2Compatible release (~=1.2 means >=1.2,<2.0)requests~=2.31
package[extra]With optional dependenciesrequests[security]
-r other.txtInclude another requirements file-r base.txt
-e ./local-pkgEditable install from local path-e ./my-library

Common Use Cases

  • New project setup: Generate a requirements.txt with common packages for your project type (web API, data science, machine learning, CLI tool, scraping)
  • Environment reproducibility: Pin exact versions to ensure all team members and CI/CD pipelines use identical package versions
  • Docker image building: Include requirements.txt in Docker builds for consistent, reproducible container images
  • Virtual environment documentation: Document which packages a virtual environment contains for onboarding new developers
  • Dependency auditing: Review installed packages for known vulnerabilities using tools like pip-audit or safety

Best Practices

  1. Pin exact versions in production — Use == for production requirements to ensure reproducible deployments. Generated with: pip freeze > requirements.txt
  2. Use separate requirements files — Maintain requirements.txt (production), requirements-dev.txt (development tools), and requirements-test.txt (testing dependencies).
  3. Audit dependencies regularly — Run pip-audit or safety check to scan for packages with known CVEs. Set up automated scanning in CI/CD.
  4. Use virtual environments always — Never install project dependencies globally. Use venv, virtualenv, or conda to isolate project dependencies.
  5. Consider modern alternatives — For new projects, evaluate pyproject.toml (PEP 621) with pip, Poetry, or PDM as more modern dependency management approaches that offer lock files and dependency resolution.
  6. Hash-check for security — Use --require-hashes with pip to verify package integrity: pip install --require-hashes -r requirements.txt. This prevents supply chain attacks through tampered packages.

Frequently Asked Questions

What is the difference between == and ~= version specifiers?+

== pins an exact version (flask==2.3.0). = allows compatible releases (flask=2.3.0 allows 2.3.x but not 2.4.0). >= allows any newer version. Use == for reproducible builds, ~= for patch updates, and >= cautiously.

Should I pin all dependencies or use ranges?+

For applications, pin exact versions for reproducibility. For libraries, use ranges to avoid conflicts with other packages. Always use a lock file (pip-tools, poetry.lock) to capture the full dependency tree.

How do I export my current environment to requirements.txt?+

Use pip freeze > requirements.txt. For cleaner output without subdependencies, use pip-compile from pip-tools or pipreqs to scan imports in your code. Poetry users can export with poetry export.

What are extras and how do I specify them?+

Extras are optional dependencies for specific features. Specify them in brackets: fastapi[all], pytest[dev]. This installs the main package plus additional dependencies for that feature set.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.