Skip to main content

A simple (and fast) requirements.txt file generator.

Project description

A simple (and fast) requirements.txt file generator

PyPI - Version PyPI - Implementation PyPI - Python Version PyPI - Status Static Badge Static Badge Static Badge PyPI - License PyPI - Wheel

The preqs project is a cross-platform, simple, fast and easy-to-use requirements file generator. Your project's imported dependencies are collected into a requirements.txt file. No more, no less.

Installation

Installing preqs is quick and easy. As a design feature, the library does not have any external (non-built-in) dependencies.

pip install preqs

Usage

The help (or usage) menu can be displayed, as below, using the following command from the terminal:

preqs --help

Which displays:

usage: preqs [PATH] [options]

A simple (and fast) requirements.txt file generator.

positional arguments:
  PATH                  Path to the project's root directory.
                        Alternatively, the path where the search for modules should start.
                        Defaults to the current directory.

options:
  -d, --debug           Print verbose debugging output while processing.
  -i IGNORE_DIRS [IGNORE_DIRS ...], --ignore_dirs IGNORE_DIRS [IGNORE_DIRS ...]
                        One or more director(y|ies) to be ignored when collecting module files.
  -p, --print           Print the detected requirements, rather than creating a file.
  -r, --replace         Replace the current requirements.txt file.
                        
  -h, --help            Display this help and usage, then exit.
  -v, --version         Display the version and exit.

preqs <installed version>

Usage Example

In its simplest form, preqs can be run by just calling the program from within your project's root directory, without any arguments. The path from which the Python module discovery begins defaults to the current directory. If your project is in another directory, pass that directory's path into the PATH argument. The requirements file is saved into the path provided.

Notes:

  • The following examples assume you are already in your project's root directory, therefore PATH is not provided.
  • Any of the following flags may be combined to form your own requirements cocktail.

Case 1: Simplest form

Simply generate a requirements file for your project, as:

  1. Run preqs as:
preqs
  1. Check the current directory for a requirements.txt file containing the project's external dependencies.

Case 2: Ignoring directories

If you wish to exclude a directory (or directories) from the requirements file, the --ignore_dirs flag may be used as:

  1. Run preqs as:
preqs --ignore_dirs docs build
  1. Check the current directory for a requirements.txt file containing the project's external dependencies.

Case 3: Display only (do not generate a file)

In some cases, for example with an existing requirements file you do not want to overwrite, you may wish to display the requirements to the terminal. This can be accomplished using the --print flag, as:

  1. Run preqs as:
preqs --print
  1. Watch the terminal for an output displaying the project's requirements.

Case 4: Overwrite an existing requirements file

By default, if a requirements.txt file exists, you will be alerted. The existing file will not be overwritten. That is, unless you tell preqs it's OK.

  1. Run preqs as:
preqs --replace
  1. Check the current directory for a new requirements.txt file containing the project's external dependencies.

Additional information

How is the version number obtained?

The version number you see in the requirements file output is obtained using the built-in importlib library. Therefore, the package must be installed in the environment being used to run preqs.

  • By design, we do not use PyPI to obtain version numbers as this practice usually involves assuming the latest version - whereas this may not be the case for your project.
  • Any packages which are known to be imported by the project, and yet do not appear in the requirements file, are likely not installed in the environment. Run preqs with the --print flag to observe any packages which are imported for which the version number could not be obtained. These 'unknown version' packages are (currently) ignored when the requirements file is written.

I don't see a specific package in the requirements file.

Refer to the How is the version number obtained? question.

Why should I not just use pip freeze?

Many online 'tutorials' for generating a requirements file say to use pip freeze and redirect the output to a file called requirements.txt. However, this is not good practice for the following reasons:

  • All of the packages installed in your development environment will be listed in the requirements file. This may include some (or many) packages which your project does not require, thus bloating the end-user's installation and thereby cluttering their environment. Or, the packages you have in your environment, although not used by the project, may be out-of-date; causing the end-user to be forced to install out-of-date packages.
  • A true requirements file should contain only those packages which are imported and required by the project.
  • Only the packages that were installed with pip install will be included in the requirements file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

preqs-0.1.0b4.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

preqs-0.1.0b4-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file preqs-0.1.0b4.tar.gz.

File metadata

  • Download URL: preqs-0.1.0b4.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for preqs-0.1.0b4.tar.gz
Algorithm Hash digest
SHA256 700a7f3201c65eaccfa2a3071789fbf80a8dc65e08186909403b956b7f6b6b3a
MD5 d5eca93c21741893c79bde9fcbf91f72
BLAKE2b-256 4d4a418cc76b69a08effbaec94ef9046148fd260d245ff9c6e8f13f923b9d9af

See more details on using hashes here.

File details

Details for the file preqs-0.1.0b4-py3-none-any.whl.

File metadata

  • Download URL: preqs-0.1.0b4-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for preqs-0.1.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 99a54c939787b4c5573b2ad89a9040fbc2ab1e2d27b84b4eeb01008817fd67ac
MD5 1279a41906801b8b8b07a43b27824b91
BLAKE2b-256 f08238d6e4c047b2ec4f0561084b304b3a2e82ea1be2fe6839fa88df6a5400bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page