Skip to main content
Learn how to use 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 both pixi.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:
Pixi supports both flat and src layouts.

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

The requires-python field automatically manages Python:
This is equivalent to in pixi.toml:
Pixi automatically installs the appropriate Python interpreter - no system installation needed!

Version Constraints

Dependency Management

PyPI Dependencies

Dependencies in the [project] section become PyPI dependencies:
Add dependencies using:

Conda Dependencies

Use [tool.pixi.dependencies] for conda packages:
Add conda dependencies:

Mixing Both Sources

Pixi seamlessly handles packages from both sources:

Priority Rules

When the same package is in both sections:
Conda dependencies always take precedence over PyPI dependencies.

Optional Dependencies and Features

Optional Dependencies (Legacy)

Define optional dependency groups:
Pixi automatically converts these to features:
Result:

Dependency Groups (PEP 735)

The modern approach using dependency groups:
Add to a dependency group:

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:
Add environments:

Solve Groups

Solve groups ensure dependency versions are consistent across environments:
Environments in the same solve group share the same dependency versions, ensuring consistency between development and testing.

Tasks

Define Tasks

Create reusable commands:
Run tasks:

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

Benefits:
  • Modern and fast
  • Minimal configuration
  • Good defaults for most projects

Setuptools

Poetry

Complete Example

Here’s a complete pyproject.toml for a production project:

Best Practices

Always include a build-system section: Even if you’re not distributing your package, it’s required for editable installs.
Use dependency groups over optional-dependencies: The PEP 735 dependency groups are more flexible and modern.
Prefer conda for system dependencies: Use conda for packages with C/C++ dependencies, PyPI for pure Python packages.
Use solve groups for consistency: Put all environments in the same solve group to ensure version consistency.

Comparison with pixi.toml

Next Steps

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.