Flit
Flit is a simple yet effective packaging tool for pure Python packages, focusing on streamlining the process of putting modules and packages on PyPI. It handles creating source distributions (sdists) and wheels, and publishing them. The current stable version is 3.12.0, with releases occurring as needed to incorporate fixes and new features, typically following a minor version increment cadence.
Warnings
- breaking Flit 3.0 removed support for the older `flit.ini` configuration file format. Projects must now use `pyproject.toml` for all metadata.
- breaking The `flit_core` build backend, which Flit uses, now explicitly requires Python 3. This means that while Flit can package Python 2 modules, it must be run on a Python 3 interpreter.
- deprecated In Flit 3.5, the default behavior of `flit build` and `flit publish` changed; they no longer generate a `setup.py` file in the sdist by default. This makes sdists only compatible with tools supporting PEP 517.
- gotcha Flit is designed for pure Python packages without complex build steps (e.g., C extensions, bundled Javascript). If your project requires compilation or other build processes, Flit may not be the most suitable tool.
- gotcha Flit does not manage your project's dependencies directly; you must declare them in `pyproject.toml` manually. Tools like Poetry or Pipenv offer integrated dependency management.
Install
-
pip install flit
Imports
- flit
Flit is primarily a command-line tool. Direct Python imports for typical packaging tasks are not common.
Quickstart
# Create a directory for your package, e.g., 'my_package'
# Inside 'my_package', create 'my_module.py' or a package directory 'my_module/__init__.py'
# my_module/__init__.py (or my_module.py)
"""An amazing sample package!"""
__version__ = "0.1.0"
def greet(name):
return f"Hello, {name}!"
# In the root of your package directory (e.g., 'my_package')
# 1. Initialize Flit (creates pyproject.toml)
# flit init
# This would be the content of the generated pyproject.toml (adjust details):
# [build-system]
# requires = ["flit_core >=3.2,<4"]
# build-backend = "flit_core.buildapi"
# [project]
# name = "my-module-name"
# authors = [{name = "Your Name", email = "your.email@example.com"}]
# dynamic = ["version", "description"]
# classifiers = [
# "Programming Language :: Python :: 3",
# "License :: OSI Approved :: MIT License",
# "Operating System :: OS Independent",
# ]
# requires-python = ">=3.8"
# 2. Build the package (creates .whl and .tar.gz in 'dist/')
# flit build
# 3. Publish to PyPI (requires PyPI credentials setup)
# flit publish --repository pypi
# Example of using the installed package locally:
# pip install --no-index --find-links=./dist my-module-name
# import my_module
# print(my_module.greet("Flit User"))