Coherent deps (dependencies) provides insights into the dependencies used by a code base, resolving imports to the dependencies that supply those imports. The Coherent OSS community presents this library to make the functionality available for a variety of uses.
The Coherent System implements automatic dependency inference using coherent.deps, allowing Python projects to avoid the need to declare dependencies and to instead focus on the implementation.
pip-run leverages this library to enable on-demand installation of dependencies required by scripts, as implied by their imports.
See the code documentation for details. See also the usage in coherent.build for the usage by the build backend.
Design Overview
coherent.deps is implemented primarily by two modules, imports and pypi.
imports performs the function of statically analyzing code to detect imports from a codebase and separate stdlib imports from third-party packages backed by dependencies.
pypi provides the package index support, providing a mapping of imports to package names in PyPI. It leverages a world-readable MongoDB database hosted in MongoDB Atlas to implement the mapping. Each PyPI project gets an entry in the coherent builder:pypi:distributions collection.
Each entry has the following structure:
_id: the MongoDB generated unique IDid: the normalized name of the package (e.g.typing-extensionsorcherrypy)name: the package's canonical name (e.g.typing_extensionsorCherryPy)updated: The last time this package was updated from PyPIdownloads: The number of downloads in the past 30 days as returned by the pypinfo query.roots: A collection of root importable names presented by the package (e.g.requestsorcoherent.depsbut notrequests.errors).error: Any error that occurred when attempting to process the package.
Only id and downloads are required. An entry without updated is due to be updated by the process routine. An entry without roots or name has never been processed.
Maintaining the mapping
There is a subpackage, distributions, which contains two scripts, load and process (invoked by python -m coherent.deps.distributions.{load,process}) to load the distributions from a "top downloads" summary and then process those by loading their data from PyPI.
To get the full set of "top downloaded" packages that contain at least one download, run this query:
🐚 pipx run pypinfo --json --indent 0 --limit 800000 --days 30 "" project > ~/Downloads/top-pypi-packages-30-days.json
Note that this pypinfo script requires a Google API key and with a very high limit like 800000, will cost several dollars to run, so the maintainer only runs it about twice a year.
Then, to refresh the database with the downloaded dataset:
🐚 pip-run coherent.deps -- -m coherent.deps.distributions.load ~/Downloads/top-pypi-packages-30-days.json
This process will ensure that all packages are up-to-date with their latest download stats.
From there, ensure that any newly-added packages are processed:
🐚 pip-run coherent.deps -- -m coherent.deps.distributions.process
Note that only those entries without an updated field will be processed. To re-process packgaes that may have grown stale, clear the updated field on those entries. For example, to mark stale any entries older than 6 months:
max_age = datetime.timedelta(days=6*30)
filter = {'updated': {'$lt': datetime.today() - max_age}}
op = {'$unset': 'updated'}
collection.update_many(filter, op)
Thereafter, re-run the process routine, which will re-process the packages without the updated field.
Release files for coherent.deps 1.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| coherent_deps-1.7.0.tar.gz | 15.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| coherent_deps-1.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.8 kB
Release files / coherent_deps-1.7.0.tar.gz
| Download URL | coherent_deps-1.7.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64f1968e2e3859ea23dc397362a0547be96a655dbb92434b522026e5d9e18720
|
|
BLAKE2b-256 checksum How to use checksums |
1d8044902b13dee628f80d927dd9ded481ab45e5133cdbced98f42b84682062d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / coherent_deps-1.7.0-py3-none-any.whl
| Download URL | coherent_deps-1.7.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13dc3d7045d2d22356b5766b069ca0175178ba8ad56ca58e507621de27e668ca
|
|
BLAKE2b-256 checksum How to use checksums |
5b7a785492488c06dea377dc69a7831e1aca4adcbb3580db708f1e3585d49b6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|