Python Quickstart
Get started with A5 in Python by installing the package and running a simple example.
Installation
Install the A5 package using pip:
pip install pya5
Or using uv:
uv add pya5
Example: Generate A5 Cells
Here's a complete example that generates A5 cells at a specified resolution and outputs them as GeoJSON:
from a5 import bigint_to_hex, cell_to_boundary, cell_to_children
# Generate all cells at the specified resolution
resolution = 2
cells = []
cell_ids = cell_to_children(0, resolution)
# Generate boundary for each cell
for cell_id in cell_ids:
boundary = cell_to_boundary(cell_id)
cells.append({
"type": "Feature",
"geometry": { "type": "Polygon", "coordinates": [boundary] },
"properties": { "cellIdHex": bigint_to_hex(cell_id) },
})
# Create GeoJSON FeatureCollection
geojson = { "type": "FeatureCollection", "features": cells }
Example Output
The above code will produce a collection of cells that cover the whole world.
Note that the cells all have the same area (approximately) shape - they are just warped by the map projection
A5 Wireframe Example
Cells shown: 240
Hover over cells to see their IDs
Usage
The code above in CLI form is available here.
python index.py 2 a5.geojson
Or if you're using uv in a project:
uv run index.py 2 a5.geojson
This will generate A5 cells at resolution 2 and save them as GeoJSON in a5.geojson
.
Next Steps
- Learn more about A5 indexing
- Explore cell hierarchy
- Check out more examples