# Flit: Python Build and Publish Tool

Flit is a Python packaging tool for building and publishing pure-Python packages. It provides a CLI for scaffolding (`flit init`), local installation (`flit install`), and PyPI publishing (`flit publish`). Its build backend, flit-core, ships as a separate package with zero runtime dependencies and can be used independently of the flit CLI.

Flit does not manage virtual environments or resolve dependencies; those are handled by separate tools such as [uv](https://pydevtools.com/handbook/reference/uv.md).

## When to use Flit

Flit suits pure-Python libraries that have no C extensions and want a direct path from source to PyPI with minimal configuration. It requires less boilerplate than [setuptools](https://pydevtools.com/handbook/reference/setuptools.md) and has no lock file or virtualenv features to configure around.

For packages with C extensions or compiled code, use [setuptools](https://pydevtools.com/handbook/reference/setuptools.md). For full project management with virtual environments, dependency locking, and publishing in one tool, use [uv](https://pydevtools.com/handbook/reference/uv.md) or [hatch](https://pydevtools.com/handbook/reference/hatch.md).

## Key Features

### Building and publishing

Flit builds [source distributions](https://pydevtools.com/handbook/reference/sdist.md) and [wheels](https://pydevtools.com/handbook/reference/wheel.md) from a pure-Python package and publishes them directly to PyPI with `flit publish`. It handles PyPI authentication via the standard `~/.pypirc` file or environment variables and supports TestPyPI as a target.

### Configuration

Flit reads project metadata from [pyproject.toml](https://pydevtools.com/handbook/reference/pyproject.toml.md) following [PEP 621](https://pydevtools.com/handbook/explanation/what-is-pep-621-compatibility.md). The package version comes from the `version` field in `pyproject.toml` or from the `__version__` attribute in the package's `__init__.py`. Data files committed alongside the Python source are included automatically.

## flit-core build backend

flit-core is Flit's [build backend](https://pydevtools.com/handbook/explanation/what-is-a-build-backend.md), distributed as a separate package with zero dependencies. It implements the [PEP 517](https://pydevtools.com/handbook/explanation/what-is-pep-517.md) build-system interface and can be used independently of the flit CLI, including in [uv](https://pydevtools.com/handbook/reference/uv.md) projects:

```bash
uv init --build-backend flit my-lib
```

This generates a `pyproject.toml` with flit-core as the build backend:

```toml {filename="pyproject.toml"}
[build-system]
requires = ["flit_core>=3.4"]
build-backend = "flit_core.buildapi"
```

flit-core handles pure-Python packages only. Its zero-dependency footprint makes it a common backend choice for packages that need lightweight builds with no transitive install overhead.

## Pros

- Zero-dependency build backend (flit-core) keeps CI and build environments lean
- Less configuration than [setuptools](https://pydevtools.com/handbook/reference/setuptools.md) for pure-Python packages
- [PEP 621](https://pydevtools.com/handbook/explanation/what-is-pep-621-compatibility.md)-compatible metadata; no proprietary config format
- Direct publishing to PyPI without a separate upload tool like [twine](https://pydevtools.com/handbook/reference/twine.md)

## Cons

- No support for C extensions or compiled code
- No virtual environment management or dependency locking
- Version must come from `__version__` in `__init__.py` or from pyproject.toml; no dynamic versioning hooks
- Smaller contributor base and slower release cadence than [setuptools](https://pydevtools.com/handbook/reference/setuptools.md)

## Learn More

- [Flit documentation](https://flit.readthedocs.io/en/latest/)
- [Why use Flit?](https://flit.pypa.io/en/latest/rationale.html)
- [What is a build backend?](https://pydevtools.com/handbook/explanation/what-is-a-build-backend.md)
- [What is a build frontend?](https://pydevtools.com/handbook/explanation/what-is-a-build-frontend.md)
- [What is PEP 621?](https://pydevtools.com/handbook/explanation/what-is-pep-621-compatibility.md)
- [What is PEP 517?](https://pydevtools.com/handbook/explanation/what-is-pep-517.md)
- [setuptools](https://pydevtools.com/handbook/reference/setuptools.md): for packages with C extensions
- [hatch](https://pydevtools.com/handbook/reference/hatch.md): for full project management
- [Example Flit package](https://github.com/python-developer-tooling-handbook/demo-flit)
