This repository demonstrates a Python monorepo structure using uv
workspaces to manage multiple interdependent packages.
This monorepo contains three packages:
-
common
: Representing sshared functionality -
cli
: Skeleton project that depends on common -
api
: Skeleton project that depends on common
The uv tool is used to manage dependencies, environments, and execution across packages.
project-root
├── pyproject.toml
└── packages/
├── api/
│ ├── pyproject.toml
│ └── src/
│ └── api/
│ ├── __init__.py
│ └── main.py
├── cli/
│ ├── pyproject.toml
│ └── src/
│ └── cli/
│ ├── __init__.py
│ └── main.py
└── common/
├── pyproject.toml
└── src/
└── common/
├── __init__.py
└── datetime_lib.py
The CLI and API packages both import and use shared functionality from the common
package.
Sync dependencies across the workspace:
uv sync
Run modules from specific packages:
uv run --package common python -m common.datetime_lib
uv run --package api python -m api.main
uv run --package cli python -m cli.main
To initialize a new package in the workspace, use:
uv init packages/core --package
This will create a new core
package scaffold under packages
.
This project follows a multipackage monorepo structure, which typically includes:
- Two or more packages located in a single repository
- Logical separation of functionality across packages (e.g.
common
,cli
,api
) - Shared tooling and dependency management (in this case, via
uv
) - Packages that may have interdependencies (e.g.
cli
andapi
both depend oncommon
) - Multiple entrypoints. Packages are peers and there is no "root" package (e.g.
cli
andapi
can both be entrypoints) - Centralized development and testing across all packages
Each package:
- Resides in its own subdirectory (e.g.
packages/common
) - Has its own
pyproject.toml
- Participates in the shared
uv
workspace defined in the top-leveluv
configuration
This setup enables better modularity, easier reuse of code, and simpler dependency/version management across internal packages.
If you use PyCharm as IDE, some configurations are also provided.