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 syncRun modules from specific packages:
uv run --package common python -m common.datetime_libuv run --package api python -m api.mainuv run --package cli python -m cli.mainTo initialize a new package in the workspace, use:
uv init packages/core --packageThis 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.
cliandapiboth depend oncommon) - Multiple entrypoints. Packages are peers and there is no "root" package (e.g.
cliandapican 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
uvworkspace defined in the top-leveluvconfiguration
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.