Skip to main content

Simple Python build backend for large codebases

Project description

PyPI

🧱 Flexbuild

Simple Python build backend for large codebases.

Add to your pyproject.toml:

[build-system]
requires = ["flexbuild"]
build-backend = "flexbuild"

Features

  • 🤸 Flexible source layouts: Place code directly alongside pyproject.toml or in a subfolder like src/module.
  • 🏷️ Virtual namespaces: Define namespace modules like org.department.package without nested folders.
  • 🏗️ Monorepo support: Handle hierarchies of hundreds of packages with minimal boilerplate.
  • 📝 Rich metadata: Entry points, optional dependencies, author and maintainer list, license, and more.
  • 🤝 Ecosystem integration: Integrates seamlessly with packaging tools like uv and pip.
  • 🐣 Hackable: Under 500 lines of easy-to-read Python code with extensive test coverage.

Options

[build-system]
requires = ["flexbuild"]
build-backend = "flexbuild"
module-folder = "."
include = [
    '*.py',
    'pyproject.toml',
    'README.md',
    'README.rst',
]
exclude = [
    'dist',
    'build',
    '__pycache__',
    '.*',
    '*/.*',
    '*.pyc',
]

Monorepos

Flexbuild supports large repositories that contain hundreds of packages with minimal boilerplate. For example, packages can be organized into a folder hierarchy:

repo
  org
    department1
      package1
        pypackage.toml  # project.name = "org.department1.package2"
        __init__.py     # import org.department1.package1
        README.md
        code.py
      package2
        pypackage.toml
        __init__.py
        ...
      package3
    department2
      package1
      package2
      package3

Optionally, create a file repo/pyroot.toml. This enables checks that package namespaces match the folder hierarchy. It also allows specifying [build-system] defaults that nested pyproject.toml files inherit.

Consider using this layout together with uv path dependencies. Unlike uv workspace dependencies, it allows teams to update their version locks independently, so they can move faster and more predictably.

Background

Expand the sections below to to learn details of how Flexbuild solves problems of other Python build backends.

Flexible source layouts

Many Python build backends require a separate module folder inside the package:

package
  pyproject.toml
  src
    module
      __init__.py

Flexbuild looks for the module code at build-system.module-folder = "." from pyproject.toml, which defaults to the package folder but can also be set to a nested folder like src/module.

Virtual namespaces

To define namespace packages that can be imported as import org.department1.package1, many Python build backends require creating nested folders inside the package:

package
  pyproject.toml  # project.name = "org-department1-package1"
  src
    org
      department1
        package1
          __init__.py

Flexbuild allows specifying namespace packages without the nested folders, simply by setting project.name = "org.department1.package1" in the pyproject.toml. This allows simpler folder structures, for example:

package
  pyproject.toml  # project.name = "org.department1.package1"
  __init__.py

Monorepos

To manage a repository with many namespace packages, most Python build backends would require duplicating the same nested folder structure inside of each package:

repo
  org-department1-package1
    pyproject.toml
    README.md
    src
      org
        department1
          package1
            __init__.py
            code.py
  org-department1-package2
    pyproject.toml
    README.md
    src
      org
        department1
          package2
            __init__.py
            code.py
  org-department1-package2
    pyproject.toml
    README.md
    src
      org
        department1
          package3
            __init__.py
            code.py
  org-department2-package1
    ...
  org-department2-package2
    ...
  org-department2-package3
    ...

Through virtual namespaces, Flexbuild allows using a directory structure for namespace packages that can still import each other as import org.department1.package1:

repo
  org-department1-package1
    pyproject.toml
    README.md
    __init__.py
    code.py
  org-department1-package2
    pyproject.toml
    README.md
    __init__.py
    code.py
  org-department1-package2
    pyproject.toml
    README.md
    __init__.py
    code.py
  org-department2-package1
    ...
  org-department2-package2
    ...
  org-department2-package3
    ...

Moreover, it allows placing the packages as leaves of a folder structure. Note that the pyproject.toml files are inside the leaf folders now. This enables organizing packages in a shared folder structure (instead of duplicating the folder structure inside of each package):

repo
  org
    department1
      package1
        pyproject.toml
        README.md
        __init__.py
        code.py
      package2
        pyproject.toml
        README.md
        __init__.py
        code.py
      package3
        pyproject.toml
        README.md
        __init__.py
        code.py
    ...

Questions

Please open a separate GitHub issue for each question.

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

flexbuild-0.2.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

flexbuild-0.2.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file flexbuild-0.2.2.tar.gz.

File metadata

  • Download URL: flexbuild-0.2.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for flexbuild-0.2.2.tar.gz
Algorithm Hash digest
SHA256 07ef24f5f3a49e447d06b282827690937e57b48f1a9efe4401dfdfeba04230e7
MD5 83dd7f0f97d10449ca3b6c07a53c9e0e
BLAKE2b-256 3f33b0c147c07fec34ca5704f9e2120a1a5950efb1899cf03e7fecf57ebbc49c

See more details on using hashes here.

File details

Details for the file flexbuild-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: flexbuild-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for flexbuild-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 454cbef58961c87645728df36c67da78321065ea0cdd6b1fe2a3a3cd9833bccb
MD5 8af2dbc4774e02f96b314b1703ddeb1f
BLAKE2b-256 d1da03d36ecb21321c6a3dcf46c7a9df418ac82de4227c355314423631db1e9e

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