pymapflights
Asynchronous Python client for the map.flights API.
Unofficial. This library is not made or endorsed by map.flights. It is the API layer of the Home Assistant integration ha-mapflights.
Installation
pip install pymapflights
Usage
import asyncio
from aiohttp import ClientSession
from pymapflights import MapFlights
async def main() -> None:
async with ClientSession() as session:
client = MapFlights(
"YOUR_API_KEY",
session=session,
user_agent="my-app/1.0 (+https://example.com)",
)
result = await client.near(48.11, 16.57, 25, limit=100)
print(f"{result.total} aircraft within 25 km")
for aircraft in result.aircraft:
print(aircraft.callsign, aircraft.distance_km, aircraft.alt_baro)
print(client.attribution)
asyncio.run(main())
Notes:
totalis the number of aircraft in the radius;aircraftis capped bylimit(API default 50, max 500).result.truncatedtells you when the list is incomplete.- When
result.readyisFalse, a delayed tariff is still filling its buffer and the empty list does not mean there is no traffic. - The session belongs to you; the client never closes it.
Endpoints
| Method | Endpoint | Stability | Quota |
|---|---|---|---|
near(lat, lon, radius_km, limit=) |
/near/{lat}/{lon}/{radius} |
stable | live (1 per 5 s) |
aircraft_flights(hex_id, limit=) |
/aircraft/{hex}/flights |
stable | daily |
airlines(query=, limit=, offset=) |
/airlines |
stable | daily |
me() |
/me |
experimental | daily |
day_board(airport, "arr" | "dep", day=) |
/airports/{icao}/day-board |
experimental | daily |
flight_by_callsign(callsign) |
/flights/by-callsign/{callsign} |
experimental | daily |
Experimental endpoints may change within /api/v1; their models make every
field optional. key_prefix(api_key) returns the non-secret key prefix
(mf_live_ + 8 hex) without a request.
flight_by_callsign() raises MapFlightsNoCurrentFlightError when there is
no current flight (reason is no current flight with last_flight, or
unknown flight). That is a normal state, but it still counts against the
daily quota. A landing appears there only 20 to 35 minutes after touchdown.
API keys and terms
Keys are issued by map.flights (operators of a receiving station can create a
free key at https://map.flights/account/api-key). Use of the API is subject to
the map.flights API terms. Attribution is
mandatory: show at least "Data: map.flights"; the full text of the last response
is in client.attribution.
Rate limits
The client enforces the limits per key, shared by every client in the process that uses the same key:
- Live (
near): one request every 5 s. A call waits for its slot. Every call uses the slot, even one that fails (anearoutside the key's area too). - Minute: at most 60 requests per minute over all endpoints.
- After a 429 the client remembers
Retry-Afterfor that scope (live,minuteorday) and refuses further requests of that scope until then.
A refused request raises MapFlightsRateLimitError with local=True and is
never sent. retry_after and scope are set either way.
client.live_rate_limit and client.daily_rate_limit hold the
X-RateLimit-* headers of the last live and the last other response. For live
requests they describe the live bucket, not the daily quota, so
client.remaining_today only comes from non-live responses.
Errors
| Exception | When |
|---|---|
MapFlightsAuthError |
401, unknown or revoked key |
MapFlightsOutOfAreaError |
403 out_of_area |
MapFlightsKeyDormantError |
403 key_dormant |
MapFlightsNotInTariffError |
403 group_not_in_tariff, endpoint_not_in_tariff, format_not_in_tariff |
MapFlightsTariffError |
base class of the 403 errors above, also for unknown codes |
MapFlightsNotFoundError |
404 (parsed body in body) |
MapFlightsNoCurrentFlightError |
404 of flight_by_callsign, a normal state |
MapFlightsRateLimitError |
429, or refused locally (local=True) |
MapFlightsConnectionError |
timeout or network error |
MapFlightsError |
base class of everything above |
Development
uv sync
uv run pytest
uv run ruff check .
uv run ruff format --check .
uv run mypy
License
MIT
Metadata
Release files for pymapflights 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymapflights-0.2.0.tar.gz | 21.0 kB | With provenance | Details for pymapflights-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymapflights-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pymapflights-0.2.0-py3-none-any.whl |
Total release size: 37.1 kB
Release files / pymapflights-0.2.0.tar.gz
| Download URL | pymapflights-0.2.0.tar.gz |
|---|---|
| Size | 21.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e390956806e4d67b4b90feec373c1b8a3de5be8a6aa395a3bee2c56b3ab6427c
|
|
BLAKE2b-256 checksum How to use checksums |
7649a4592ea76a771241fcdc88fef0af6a434dd7cb81fb5d57149dd29383f205
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logRelease files / pymapflights-0.2.0-py3-none-any.whl
| Download URL | pymapflights-0.2.0-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a7367495c0d83e3b063df933d8e31f36b9e5616f5bc8d4caeab8250de388f30
|
|
BLAKE2b-256 checksum How to use checksums |
48241739bbe1adc3d1200a834c327ac5c3c22968741545f83841b7ac6e3f4bff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logSecurity for pymapflights 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pymapflights-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.