skillfed

hatch-polylith-bricks

Hatch build hook plugin for Polylith

hatch-polylith-bricks v1.5.7 299.6K downloads/30d#7,857 on PyPI553
Permissive license MIT Active released

What it is and what it does

This package is a Hatch build hook that bridges Polylith architecture—a modular monorepo pattern—with Python packaging. It reads brick definitions from your pyproject.toml (paths to bases and components in your Polylith workspace) and ensures they are correctly included in built wheels and source distributions. The hook also solves a real packaging problem: when multiple libraries built from the same monorepo share the same top-level namespace, they collide when installed in the same environment. This hook can rewrite imports during packaging to add a custom namespace wrapper, preventing those collisions.

The rewriting uses Python's ast module to parse and modify source code, injecting a custom top namespace into all imports. Without a custom namespace configured, the hook simply includes bricks as-is. It's designed for teams using Polylith who need to publish multiple independent libraries from a single workspace without namespace conflicts.

Use it for:

  • Publishing multiple Python libraries from a Polylith monorepo without namespace collisions when installed together.
  • Automatically including Polylith bricks in wheel and sdist distributions during Hatch builds.
  • Adding a custom namespace prefix to library code during packaging to isolate it from other monorepo libraries.
  • Simplifying build configuration for Polylith workspaces by automating brick discovery and inclusion.
  • Rewriting internal imports in source code to reflect a different namespace structure in the published package.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A Hatch build hook that integrates Polylith architecture bricks into Python packages and optionally rewrites imports to add a custom namespace during packaging.

Yes, if you are using Hatch as your build backend and Polylith as your monorepo architecture. The hook solves the specific problem of packaging multiple libraries from one workspace without namespace conflicts. Install friction is low, maintenance is active, and there are no known vulnerabilities. Not relevant if you are not using Polylith or a different build system.

Install

hatch-polylith-bricks on PyPI

pip

pip install hatch-polylith-bricks

uv

uv add hatch-polylith-bricks

poetry

poetry add hatch-polylith-bricks

Installing hatch-polylith-bricks

Before you install

Low friction: pure Python wheel with only two lightweight runtime dependencies (hatchling and tomlkit). Active maintenance with a recent release 42 days ago and no security vulnerabilities.

License in practice

MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions.

Quickstart

Add to pyproject.toml:

[build-system]
requires = ["hatchling", "hatch-polylith-bricks"]
build-backend = "hatchling.build"

[tool.hatch.build.hooks.polylith-bricks]
# Section enables the hook

[tool.polylith.bricks]
"../../bases/my_namespace/my_base" = "my_namespace/my_base"

Then run: hatch build

Requires Hatch as your build backend and a Polylith workspace structure with bricks in bases/ and components/ directories.

Verify before relying

  • Whether AST-based import rewriting handles all Python import patterns (relative imports, star imports, etc.)
  • Performance impact when rewriting large codebases with many bricks
  • Compatibility with Polylith workspaces using non-standard directory layouts

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 2 — hatchling, tomlkit
Maintenance actively maintained — 42 days since the last release
Last repo commit
First released
Downloads 299,580/month — #7,857 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: hatch_polylith_bricks-1.5.7-py3-none-any.whl

Framework :: HatchLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

hatch build hook polylithpolylith bricks packagingmonorepo namespace collisionhatch plugin architecturepython polylith integrationcustom namespace packagingpolylith workspace build
monorepopolylith-architecturehatch-plugin

More Build Tools packages