[Python] Get app version from pyproject.toml inside python code

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am not very familiar with python, I only done automation with so I am a new with packages and everything.
    I am creating an API with Flask, Gunicorn and Poetry.
    I noticed that there is a version number inside the pyproject.toml and I would like to create a route /version which returns the version of my app.
    My app structure look like this atm:

    ├── README.md
    ├── __init__.py
    ├── poetry.lock
    ├── pyproject.toml
    ├── tests
    │ └── __init__.py
    └── wsgi.py


    Where wsgi.py is my main file which run the app.

    I saw peoples using importlib but I didn't find how to make it work as it is used with:
    __version__ = importlib.metadata.version("__package__")
    But I have no clue what this package mean.

    Continue reading...

Compartilhe esta Página