Why Python Packages?
- To make Python code installable, reusable and distributable via PyPI or TestPyPI, one must package the code.
- The Package should have modules (.py file(s)) and init.py file.
- The code must be versioned.
- Project dependencies must be managed.
- The project’s metadata must be clearly defined.
Why choose Pixi for Python Packaging ?
- Choose a tool with good support and long term vision.
- Choose a tool suitable for your project.
- Focus on PEP specifications and recomendations.
Set up a project directory
- Follow the appropriate folder structure.
- Always include the
__init__.pyfile in packages. - Sequence of Pixi commands: init → add → run → remove → lock → install → update.
- Define / check
[project],[dependencies]and[tasks]in yourpyproject.tomlfile. - Keep your project dependencies lean and remove unused packages.
Metadata for Python packging
- Every project must include a
pyproject.tomlfile - The
[build-system]section is required and must define bothrequiresandbuild-backend. - The
[project]section must, at minimum, include the projectnameandversion. - It is recommended to specify dependencies in the
[project]section for clarity and reproducibility. - Use semantic versioning (MAJOR.MINOR.PATCH) for versioning your packages.
How to publish your Python project
- Ensure all metadata is filled in and choose a unique project name.
- Use
buildto generate distribution files - Create a TestPyPI account and generate an API token
- Use
twine uploadto securely publish your package. - Test your package by installing it from TestPyPI via
pip install.
Extra
- Define tasks such as
startin yourpixi.tomlorpyproject.toml. - Use
pixi run <task-name>to execute those tasks. -
pixi run startensures consistency and reproducibility when launching a project. - Yank a faulty release and provide useful comments for why you yanked it.
