[Python] How to specify package as an extra in poetry/pyproject.toml

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a package with a pyproject.toml that has a core package & an optional GUI package with its own extra dependencies. This is the project structure:

    .
    └── my_project/
    ├── src/
    │ └── my_package/
    │ ├── core/
    │ │ └── __init__.py
    │ ├── gui/
    │ │ └── __init__.py
    │ └── __init__.py
    ├── poetry.lock
    └── pyproject.toml


    PEP 771 specifies how extras can be installed using square brackets. I have found plenty of resources on how to install extras, but frustratingly none on how to define them in your own project.

    How do I set up my project so that a user installing with poetry add my_package installs just the core package, but poetry add my_package[gui] installs both core and gui?

    Continue reading...

Compartilhe esta Página