pyproject.toml as your Pixi manifest file for Python projects, combining standard Python packaging with Pixi’s powerful environment management.
Why pyproject.toml?
Pixi supports bothpixi.toml and pyproject.toml manifest formats. For Python projects, pyproject.toml is recommended because:
- It’s the standard format for Python projects
- It integrates with existing Python tooling
- It combines project metadata with Pixi configuration
- Other Python developers will be familiar with it
For non-Python projects, use
pixi.toml instead.Initial Setup
Project Structure
A typical project structure looks like:Understanding pyproject.toml
Standard Project Metadata
The[project] section defines standard Python metadata:
Pixi Workspace Configuration
Pixi configuration lives under[tool.pixi]:
Build System
Define how to build your package:Pixi uses this when installing your package as an editable dependency. If omitted, it defaults to setuptools.
Python Version Management
Automatic Python Installation
Therequires-python field automatically manages Python:
pixi.toml:
Version Constraints
Dependency Management
PyPI Dependencies
Dependencies in the[project] section become PyPI dependencies:
Conda Dependencies
Use[tool.pixi.dependencies] for conda packages:
Mixing Both Sources
Pixi seamlessly handles packages from both sources:- pyproject.toml
- Commands
Priority Rules
When the same package is in both sections:Optional Dependencies and Features
Optional Dependencies (Legacy)
Define optional dependency groups:Dependency Groups (PEP 735)
The modern approach using dependency groups:Self-References
Dependency groups can reference each other:Environment Configuration
Single Environment
By default, Pixi creates one environment:Multiple Environments
Create separate environments for different purposes:Solve Groups
Solve groups ensure dependency versions are consistent across environments:Tasks
Define Tasks
Create reusable commands:Feature-Specific Tasks
Tasks can be scoped to features:Task Dependencies
Tasks can depend on other tasks:Development Dependencies with tool.uv.sources
For monorepo setups, use[tool.uv.sources] to reference local packages:
Project Structure
Main Project Configuration
Package A Configuration
[tool.uv.sources] only works in dependencies, not in the main manifest.Build System Options
Hatchling (Recommended)
- Modern and fast
- Minimal configuration
- Good defaults for most projects
Setuptools
Poetry
Complete Example
Here’s a completepyproject.toml for a production project:
Best Practices
Comparison with pixi.toml
Next Steps
- Explore Python development workflows
- Set up multiple environments
- Learn about importing environments
Troubleshooting
Build Backend Not Found
If you see “build backend not found”, add a[build-system] section:
Editable Install Issues
Ensure your project is in[tool.pixi.pypi-dependencies]:
Mixed Dependency Sources
If a package is in both[project.dependencies] and [tool.pixi.dependencies], the conda version takes precedence.