Skip to main content

CLI tool to gather dependencies for imports actually used by your code

Project description

realreq: real requirements for real projects

GitHub Workflow Status PyPI - Downloads GitHub code size in bytesPyPI pyversions

realreq is the lightweight tool that provides you with the actual dependencies used by your project.

Why use realreq?

Better dependency management

It is not a secret that python package management is not easy. Separating package dependencies from tool dependencies is enough to make you pull your hair out. Determining what packages are actual being used by your code, and what their dependencies are is a hassle. realreq fixes this for you by examining your source files and parsing out the dependencies for you.

Lightweight

realreq does not depend on any third party package, except for pip. It does not make any assumptions about the presence or absence of a virtual environment, or what tool you used to make your virtual environment. This means it will work with whatever tool set you are already using, without getting in the way of your workflow

Install

realreq is available for install via pip.

pip install realreq

Usage

Shallow Dependencies

By default realreq delivers a "shallow" dependency specification, giving you a list of the packages directly used by your code:

realreq -s ./path/to/mypackage > requirements.txt

This is useful for Library maintainers who want to make sure the minimal essentials are there, without over specifying the actual requirements for their library.

Deep Dependencies

Alternatively, you can get a "deep" dependency list by using the -d flag

realreq -d -s ./path/to/mypackage > requirements.txt

This is beneficial for maintaining executable/standalone programs, by defining the exact requirements under which the program will function.

Adding aliases

Due to the way python packaging works, it is possible for a python package to have a different install name than import name. Realreq works by inspecting your imports and then checking the versions they were installed with. If the names mismatch, there will be an issue with realreq being unable to find them.

This can be resolved by adding an --alias/-a flag, mapping the import name to the install name.

realreq -d -s ./path/to/mypackage -a bs4=beautifulsoup4 > requirements.txt

If you have a lot of these aliases you can also specify them in an alias-file:

cat << EOF > realreq-aliases.txt
bs4=beautifulsoup4
airflow=apache-airflow
dateutil=python-dateutil
EOF
realreq -d -s ./path/to/mypackage --alias-file realreq-aliases.txt > requirements.txt

Additional tools

Inverted Tree

Sometimes you may want to explore the reasons for certain dependencies. Realreq lets you see an inverted tree view that displays all your dependencies and what libraries they are used by. For example the inverted tree for realreq's test suite looks like this:

- attrs
  |- pytest
    |- pytest-mock
- iniconfig
  |- pytest
    |- pytest-mock
- pluggy
  |- pytest
    |- pytest-mock
- py
  |- pytest
    |- pytest-mock
- pyparsing
  |- packaging
    |- pytest
      |- pytest-mock
- tomli
  |- pytest
    |- pytest-mock

Currently realreq does not support a regular tree view, though that feature is one that I want to implement in the future.

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

realreq-0.7.4.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

realreq-0.7.4-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file realreq-0.7.4.tar.gz.

File metadata

  • Download URL: realreq-0.7.4.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for realreq-0.7.4.tar.gz
Algorithm Hash digest
SHA256 48c77e24f99f1fc550f74eb92f7c1ea28f29a7e1f387ae8b94d1b758cb283955
MD5 98a2be20afbe6bfd2ad14b734662b294
BLAKE2b-256 02b6223e689e37fbc750b53f663855070660a6b432430dd3f429e385b0287ab3

See more details on using hashes here.

File details

Details for the file realreq-0.7.4-py3-none-any.whl.

File metadata

  • Download URL: realreq-0.7.4-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for realreq-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 58fd9c3262aecac9136f99f326029084e57d1b99d4b7e37185639e8657b3519d
MD5 81665b5ce6cdb73c575c64c09db07b92
BLAKE2b-256 2d590c13ec9a065ba254aad6e3e5efd4d158efa5477cbe4b96f36ca884e2bc6f

See more details on using hashes here.

Supported by

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