yarasp

API Reference

This page provides detailed documentation for all public APIs in Yarasp.

Clients

YaraspClient

Synchronous client for accessing Yandex Schedule API.

from yarasp import YaraspClient

client = YaraspClient(**kwargs)

Parameters:

Methods:

search(params=None, auto_paginate=True)

Search for routes between stations.

Parameters:

Returns: List of route segments

Example:

results = client.search(params={
    "from": "c213",
    "to": "c2",
    "date": "2024-01-15"
})

schedule(params=None, auto_paginate=True)

Get station schedule.

Parameters:

Returns: List of schedule entries

Example:

schedule = client.schedule(params={
    "station": "s9600213",
    "date": "2024-01-15"
})

thread(params=None)

Get route thread information.

Parameters:

Returns: Thread information dictionary

Example:

thread_info = client.thread(params={"uid": "12345"})

nearest_stations(params=None, auto_paginate=True)

Find nearest stations by coordinates.

Parameters:

Returns: List of station information

Example:

stations = client.nearest_stations(params={
    "lat": 55.7558,
    "lng": 37.6173,
    "distance": 50
})

nearest_settlement(params=None)

Find nearest settlement by coordinates.

Parameters:

Returns: Settlement information dictionary

Example:

settlement = client.nearest_settlement(params={
    "lat": 55.7558,
    "lng": 37.6173
})

carrier(params=None)

Get carrier information.

Parameters:

Returns: Carrier information dictionary

Example:

carrier_info = client.carrier(params={"code": "SU"})

stations_list(params=None)

Get list of stations.

Parameters:

Returns: List of stations

Example:

stations = client.stations_list()

copyright(params=None)

Get copyright information.

Parameters:

Returns: Copyright information dictionary

Example:

copyright_info = client.copyright()

get(endpoint, params=None, auto_paginate=False, result_key=None)

Generic method to call any API endpoint.

Parameters:

Returns: API response (list if paginated, dict otherwise)

Example:

result = client.get("custom/endpoint", params={"param": "value"})

is_from_cache()

Check if the last response was retrieved from cache.

Returns: bool - True if last response was from cache, False otherwise

Example:

client.search(params={"from": "c213", "to": "c2"})
if client.is_from_cache():
    print("Served from cache!")

AsyncYaraspClient

Asynchronous client for accessing Yandex Schedule API.

from yarasp import AsyncYaraspClient

client = AsyncYaraspClient(**kwargs)

Parameters: Same as YaraspClient

Methods: All methods from YaraspClient, but they are async and must be awaited.

Example:

import asyncio
from yarasp import AsyncYaraspClient

async def main():
    client = AsyncYaraspClient()
    results = await client.search(params={
        "from": "c213",
        "to": "c2",
        "date": "2024-01-15"
    })
    print(f"Found {len(results)} routes")

asyncio.run(main())

Utilities

JSONUsageCounter

Counter for tracking API key usage stored in a JSON file.

from yarasp import JSONUsageCounter

counter = JSONUsageCounter(file_path="yarasp_counter.json")

Methods:

get_count()

Get the current usage count for today.

Returns: int - Number of API requests made today

Example:

count = counter.get_count()
print(f"Made {count} API requests today")

increment()

Increment the usage counter for today.

Returns: int - Updated count after incrementing

Example:

count = counter.increment()
print(f"Usage count: {count}")

Constants

Environment Variables


Exceptions

RuntimeError

Raised when:

NotImplementedError

Raised when trying to use Redis counter backend (not yet implemented).

ValueError

Raised when unsupported counter backend is specified.


Type Hints

Yarasp includes type hints for better IDE support and static type checking.

from yarasp import YaraspClient
from typing import List, Dict, Any

client: YaraspClient = YaraspClient()
results: List[Dict[str, Any]] = client.search(params={"from": "c213", "to": "c2"})