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__.py file in packages.
  • Sequence of Pixi commands: initaddrunremovelockinstallupdate.
  • Define / check [project], [dependencies] and [tasks] in your pyproject.toml file.
  • Keep your project dependencies lean and remove unused packages.

Metadata for Python packging


  • Every project must include a pyproject.toml file
  • The [build-system] section is required and must define both requires and build-backend.
  • The [project] section must, at minimum, include the project name and version.
  • 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 build to generate distribution files
  • Create a TestPyPI account and generate an API token
  • Use twine upload to securely publish your package.
  • Test your package by installing it from TestPyPI via pip install.

Extra


  • Define tasks such as start in your pixi.toml or pyproject.toml.
  • Use pixi run <task-name> to execute those tasks.
  • pixi run start ensures consistency and reproducibility when launching a project.
  • Yank a faulty release and provide useful comments for why you yanked it.