Skip to main content

Modular Monolith Import Checker

Overview

The Modular Monolith Import Checker is a Python utility designed to enforce modular boundaries within your codebase. It ensures that modules in a modular monolith architecture do not import each other inappropriately, maintaining clear module boundaries and a clean architecture. It can also be used to enforce modular boundaries in a monorepo and ensuring modular boundaries are enforced both locally and in CI/CD pipelines.

Features

  • Detect Forbidden Imports: Identifies cases where a module imports another module that it shouldn't.
  • Flexible Path Handling: Supports both absolute and relative paths for specifying base directories.
  • Dynamic Module List: Allows you to specify a list of modules to check.

Installation

To use the Modular Monolith Import Checker, you need Python 3 installed. Install the package using pip:

pip install module-import-checker

Usage

You can run the import checker from the command line or import it into your Python scripts.

Command-Line Interface

Run the import checker directly from the command line with various configurations:

  1. Modules at the Project Root:

    import_module_checker /path/to/project module1 module2 module3
    
    • /path/to/project is the base directory of your project.
    • module1, module2, module3, etc., are the names of the modules you want to check.
  2. Modules in the Current Directory:

    import_module_checker . module1 module2 module3
    
    • Use . if you are running the script from the project root directory.
  3. Modules Inside a Subdirectory:

    import_module_checker project_name module1 module2 module3
    
    • project_name is the name of the subdirectory containing your modules.

Example

To check imports in a project located in /home/user/myproject where modules are named auth, users, and payments, run:

import_module_checker /home/user/myproject auth users payments

You can create a bash script to run this command automatically:

#!/bin/bash
import_module_checker /home/user/myproject auth users payments

Command-Line Help

For detailed usage information, run:

import_module_checker --help

Using within a Build Process

To integrate the import checker into your CI/CD pipeline and ensure that builds fail if there are forbidden imports, you can include it in your build script. This will either pass and continue the build process or fail and exit. For example, in a GitHub Actions workflow:

name: CI

on: [push, pull_request]

jobs:
  import-check:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.x'
      
      - name: Install Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install --no-cache-dir module-import-checker
      
      - name: Run Import Checker
        run: |
          import_module_checker project_name module1 module2 module3

Example Output

Checking imports in Base Directory: /home/user/myproject
Checking module: /home/user/myproject/auth/
Import check failed with errors:
Forbidden import detected: 'users' imports 'auth' in /home/user/myproject/users/services.py

Contributing

If you would like to contribute to this project, please fork the repository and submit a pull request. Ensure that your code follows the existing style and includes tests for new features.

License

This project is licensed under the GNU General Public License - see the LICENSE file for details.

Contact

For any questions or issues, please contact abiolaadeshinaadedayo@gmail.com.

Metadata

Release files for module-import-checker 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for module-import-checker 0.0.13
File Size Uploaded Provenance
module-import-checker-0.0.13.tar.gz 16.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for module-import-checker 0.0.13
File Interpreter ABI Platform
module_import_checker-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / module-import-checker-0.0.13.tar.gz

Download URL module-import-checker-0.0.13.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2471694d9882f3058b1d37303ce65c406268e665e8df6116445f742282057b3e
BLAKE2b-256 checksum
How to use checksums
c1a1618fe37385c9538084866d52bb51c2392db2cbac302948c8e633547e106f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / module_import_checker-0.0.13-py3-none-any.whl

Download URL module_import_checker-0.0.13-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d21be3c4e4afbb88acff8d10cea3b613041260a1cad21415712e32bfdb2aa8f
BLAKE2b-256 checksum
How to use checksums
d162dec2da5ca97de5839b5036997c4346b496db5e675597d669e461fba96ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for module-import-checker 0.0.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page