Skip to main content

avia-api

CI coverage python license

Async Python client for the Aviasales / Travelpayouts Data API - historical/cached ticket prices, price calendars, and reference data (countries, cities, airports, airlines, routes).

Not covered: real-time search (Aviasales Flights Search API) and the GraphQL API - these are separate products with a different interaction model.

Installation

The package is available through any standard package manager:

pip install avia-api
# or
uv add avia-api
# or
poetry add avia-api

Requires Python 3.11+.

Quick start

import asyncio
from avia_api import AviaApiClient

async def main() -> None:
    async with AviaApiClient(token="YOUR_TOKEN") as client:
        prices = await client.prices.cheap(origin="MOW", destination="LED")
        for destination, by_index in prices.items():
            for entry in by_index.values():
                print(destination, entry.price, entry.airline, entry.departure_at)

asyncio.run(main())

You can also skip passing the token explicitly and put it in the TRAVELPAYOUTS_TOKEN environment variable - the client will pick it up automatically. Get a token in your personal dashboard: https://www.travelpayouts.com/programs/100/tools/api

Resources and endpoints

All methods return models validated by pydantic

client.prices - prices

Method Endpoint Description
cheap(origin, destination, ...) GET /v1/prices/cheap Cheapest tickets for a route
direct(origin, destination, ...) GET /v1/prices/direct Same, but direct flights only
calendar(origin, destination, depart_date, ...) GET /v1/prices/calendar Price calendar for every day of the month
monthly(origin, destination, ...) GET /v1/prices/monthly Lowest price by month
latest(...) GET /v2/prices/latest Latest found prices across the whole search base
month_matrix(origin, destination, ...) GET /v2/prices/month-matrix Price calendar for a month (v2)
week_matrix(origin, destination, ...) GET /v2/prices/week-matrix Price calendar for a week
nearest_places_matrix(origin, destination, ...) GET /v2/prices/nearest-places-matrix Prices for nearby airports/cities
Method Endpoint Description
airline(airline_code, ...) GET /v1/airline-directions Popular routes for an airline
city(origin, ...) GET /v1/city-directions Popular destinations from a city

client.reference - reference data

Public, rarely changing JSON files:

Method Endpoint
countries(language="en") GET /data/{language}/countries.json
cities(language="en") GET /data/{language}/cities.json
airports(language="en") GET /data/{language}/airports.json
airlines(language="en") GET /data/{language}/airlines.json
airline_alliances(language="en") GET /data/{language}/airlines_alliances.json
planes() GET /data/planes.json
routes() GET /data/routes.json

Client configuration

from avia_api import AviaApiClient
from pyrate_limiter import Rate, Duration

client = AviaApiClient(
    token="...",
    rate=Rate(5, Duration.SECOND),   # outgoing request rate limit (pyrate-limiter)
    max_retries=3,                   # retries on 429/5xx and connection drops
    cache_ttl=1800,                  # seconds; None disables the response cache
    cache_path="avia_api.db",        # sqlite cache file (hishel), relative path
                                      # goes under .cache/hishel/
    timeout=10.0,
)
  • Rate limiting - pyrate-limiter, a single bucket per client. Limits the rate of outgoing requests before they're sent, to avoid getting a 429 from the API.
  • Retries - tenacity with exponential backoff and jitter; on 429 the Retry-After header is honored if present, but capped at 60 seconds per attempt - an unusually large value from the server (e.g. during an incident on its side) can't stall a request indefinitely.
  • Cache - hishel on top of sqlite. Travelpayouts responses don't send Cache-Control, so FilterPolicy is used (any successful GET is cached, with entry lifetime governed by cache_ttl) instead of RFC 9111.

For tests or non-standard scenarios you can pass transport=... - your own httpx.AsyncBaseTransport, which fully disables rate limiting/retry/cache, and requests go straight through it (see respx or httpx.MockTransport).

Error handling

All exceptions derive from avia_api.AviaApiError:

Exception When it occurs
AviaApiConnectionError Network unavailable / timeout - after retries are exhausted
AviaApiAuthenticationError HTTP 401/403 - token missing or invalid
AviaApiRateLimitError HTTP 429 - after retries are exhausted; has .retry_after
AviaApiServerError HTTP 5xx - after retries are exhausted
AviaApiHTTPStatusError Other HTTP errors
AviaApiResponseError HTTP 200, but {"success": false} in the body; has .payload
AviaApiValidationError Response doesn't match the expected schema (API changed)

Logging

The library uses standard logging. To see logs, enable the desired level for the avia_api logger:

import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger("avia_api").setLevel(logging.DEBUG)

What is logged and at what level:

Logger Level Event
avia_api._transport DEBUG Delay in the rate limiter; successful request and its status
avia_api._transport WARNING Retry after a transient error/status; retry budget exhausted
avia_api._client DEBUG Outgoing request (path + query parameters) and response status
avia_api._client WARNING HTTP 401/403/429/4xx; {"success": false} in the response body
avia_api._client ERROR HTTP 5xx; network error after retries; response failed the pydantic schema

Metadata

Release files for avia-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for avia-api 0.1.0
File Size Uploaded Provenance
avia_api-0.1.0.tar.gz 16.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for avia-api 0.1.0
File Interpreter ABI Platform
avia_api-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.4 kB

Release files / avia_api-0.1.0.tar.gz

Download URL avia_api-0.1.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
263a4a31f5d91daf4e8172771eb0103305040d68a576686a5f08c04757a6523b
BLAKE2b-256 checksum
How to use checksums
af714caa3cfb342525cec14546115243af14ac4db0fdf652470745f31f3c0d49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Release files / avia_api-0.1.0-py3-none-any.whl

Download URL avia_api-0.1.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9987c35f14902bbdfaf8a04a28abef672bd17449aa8f206b37314d78d5aab01
BLAKE2b-256 checksum
How to use checksums
be97ec61930e305e504e71752181e0fc92b111ca75e08e4dd09e46e77bfa2999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Security for avia-api 0.1.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.

Select from 2 files

Attestation for avia_api-0.1.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 Sep 15, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page