Skip to main content

Keep requirements.txt in sync with what your code actually imports.

Project description

importsync

Keep requirements.txt in sync with what your code actually imports.

importsync scans every .py file in your project using Python's AST parser, figures out which third-party packages you import, and cross-references that against your requirements.txt — showing you what's missing, unused, or unpinned.

Zero runtime dependencies. Works on any Python 3.8+ project.


Install

pip install importsync

Usage

Check for drift

importsync check

Show file locations of missing imports

importsync check --locations

Fix — add missing packages automatically

importsync fix

Preview what fix would do (no writes)

importsync fix --dry-run

Fix and pin to installed versions

importsync fix --pin

Also remove unused packages (careful — may include transitive deps)

importsync fix --remove-unused

See all third-party imports found in the project

importsync scan

How it works

  1. Scan — walks all .py files and extracts every import and from ... import statement using ast.parse()
  2. Resolve — maps import names to pip package names
  3. Diff — compares the resolved set against your requirements.txt.
  4. Fix — rewrites requirements.txt, preserving comments and existing pins.

Options reference

Flag Command Description
--root DIR all Project root to scan (default: .)
--req FILE all Requirements file (default: requirements.txt)
--no-tests all Exclude tests/ directories
--locations check Show file:line for each missing import
--no-unpinned check Hide unpinned warnings
--dry-run fix Preview without writing
--pin fix Pin to installed version when adding
--remove-unused fix Remove unused entries (use with care)

License

MIT

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

importsync-0.1.5.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

importsync-0.1.5-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file importsync-0.1.5.tar.gz.

File metadata

  • Download URL: importsync-0.1.5.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for importsync-0.1.5.tar.gz
Algorithm Hash digest
SHA256 903af594deb3dc9b930ee1f327cc0a88547c3ee19c6d8c9a827ce0b97f96e442
MD5 f6f9727ac1d53d9a8fe6970dc0f252a7
BLAKE2b-256 a94ada96c2a0aa8dbce3c64a7bb78cd1788b499ef985150a7350f454f49eb69c

See more details on using hashes here.

File details

Details for the file importsync-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: importsync-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for importsync-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0436c9c1a322912f1567321d9a40898bacce927210c3503c7aaebf5454dc106a
MD5 b1f1fa26dd37a19d2e855dc8ee3aab53
BLAKE2b-256 c7a06217fff64aede541b66dd6bbe8923625a2fd5efb77761947982cab254f91

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