You can control which files and modules are included in your final distribution using packages, include, and exclude within [tool.poetry].
Including Packages
Use packages to specify modules that are not automatically detected. Poetry automatically detects a single module/package matching the project name in the root or src/ directory. If you use packages, you must explicitly include your main package.
include: The module/package name.from: The directory where the package is located (e.g., lib).to: The relative destination path upon installation.format: Restrict to sdist or wheel.
Include and Exclude Patterns
exclude: A list of patterns (globs) to ignore. Defaults to both sdist and wheel.include: A list of patterns to include. include has priority over exclude. Defaults to sdist if no format is specified.
Warning: When installing a wheel, include files are unpacked into site-packages. Avoid including top-level files like CHANGELOG.md or tests in wheels.
[tool.poetry.packages]
# Explicitly include packages
packages = [
{ include = "my_package" },
{ include = "extra_package/**/*.py" },
{ include = "my_package", from = "lib", to = "target_package" },
{ include = "my_other_package", format = "sdist" }
]
# Include/Exclude specific files
exclude = ["my_package/excluded.py"]
include = [
{ path = "tests", format = "sdist" },
{ path = "my_package/for_sdist_and_wheel.txt", format = ["sdist", "wheel"] }
]