skillfed

affine

Matrices describing affine transformation of the plane

affine v3.0.0 5.5M downloads/30d#2,094 on PyPI175
Permissive license Active released

What it is and what it does

Affine is a lightweight library for working with 2D affine transformation matrices. It provides a single core class that represents the 3x3 augmented matrix used to describe transformations like translation, rotation, scaling, and shearing in two dimensions. You construct transformations either by passing raw matrix coefficients or by using convenience class methods (identity, translation, scale, rotation, shear), then apply them to coordinate tuples using the * operator or combine multiple transformations by multiplying matrices together.

The package is particularly useful in geospatial and raster imaging workflows, where affine transformations map pixel coordinates to real-world coordinates. It includes a from_gdal() method to convert GDAL GeoTransform tuples (the standard format used by geospatial libraries) into Affine objects, and supports computing inverse transformations with the ~ operator. With only attrs as a runtime dependency and a pure-Python wheel, it installs with minimal friction.

Use it for:

  • Convert pixel coordinates to world coordinates in georeferenced raster datasets using GDAL GeoTransform data
  • Compose multiple geometric transformations (rotation, translation, scaling) into a single matrix for efficient batch application
  • Compute inverse transformations to map world coordinates back to image space in GIS workflows
  • Represent and apply 2D coordinate transformations in graphics or image processing pipelines
  • Build geospatial tools that need to work with standard affine transformation matrices from GDAL or similar libraries

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Affine provides a Python class for representing and manipulating 2D affine transformation matrices, with support for translation, rotation, scaling, and shearing operations.

Yes. Affine is a stable, actively maintained library (Production/Stable status, released 6 days ago) with no known vulnerabilities, minimal dependencies, and a clear use case in geospatial and graphics work. The permissive license and Python 3.9+ support make it safe to adopt. Install it if you work with georeferenced rasters, need to compose 2D transformations, or integrate with GDAL-based tools.

Install

affine on PyPI

pip

pip install affine

uv

uv add affine

poetry

poetry add affine

Installing affine

Before you install

Low friction: pure Python wheel with a single lightweight dependency (attrs). Active maintenance with a recent release (6 days old) and steady repository activity.

License in practice

Permissive license allows use in commercial and open-source projects without significant restrictions.

Quickstart

from affine import Affine

# Create a translation transformation
transform = Affine.translation(1.0, 5.0)

# Apply to coordinates
result = transform * (1.0, 1.0)
print(result)  # (2.0, 6.0)

# Combine transformations
combined = Affine.translation(1.0, 5.0) * Affine.rotation(45.0)

Requires Python 3.9 or later.

Verify before relying

  • Whether the package provides inverse transformation computation beyond the ~ operator shown in examples
  • Performance characteristics when applying transformations to large coordinate arrays
  • Support for 3D affine transformations or whether it is strictly 2D

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 1 — attrs
Maintenance actively maintained — 6 days since the last release
Last repo commit
First released
Downloads 5,464,538/month — #2,094 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: affine-3.0.0-py3-none-any.whl

Keywords: affine, transformation, matrix

Development Status :: 5 - Production/StableLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyTopic :: Multimedia :: Graphics :: Graphics ConversionTopic :: Scientific/Engineering :: GISTyping :: Typed

Tags

2d affine transformation matrixcoordinate transformationimage to world coordinatesgdal geotransformgeometric transformationmatrix multiplicationraster georeferencing
geospatialmatrix-mathcoordinate-transform

More GIS packages