This page provides detailed documentation for all public APIs in Yarasp.
Synchronous client for accessing Yandex Schedule API.
from yarasp import YaraspClient
client = YaraspClient(**kwargs)
Parameters:
base_url (str, default: "https://api.rasp.yandex.net/v3.0") - Base URL for API requestsverbose (bool, default: False) - Enable verbose loggingsafe_mode (bool, default: True) - Enable safe mode (raises error when daily limit exceeded)daily_limit (int, default: 500) - Daily API request limitcounter_backend (str, default: "json") - Usage counter backend ("json" or "redis")counter_storage_path (str, default: "yarasp_counter.json") - Path to JSON counter filecache_enabled (bool, default: True) - Enable HTTP cachingcache_storage (optional) - Custom cache storage backend (hishel storage instance)user_agent (str, default: "httpx") - User-Agent header for requestsMethods:
Search for routes between stations.
Parameters:
params (dict, optional) - Request parameters (from, to, date, etc.)auto_paginate (bool, default: True) - Automatically fetch all pagesresult_key (str, optional, default: "segments") - Key to extract from paginated resultsReturns: List of route segments
Example:
results = client.search(params={
"from": "c213",
"to": "c2",
"date": "2024-01-15"
})
Get station schedule.
Parameters:
params (dict, optional) - Request parameters (station, date, etc.)auto_paginate (bool, default: True) - Automatically fetch all pagesresult_key (str, optional, default: "schedule") - Key to extract from paginated resultsReturns: List of schedule entries
Example:
schedule = client.schedule(params={
"station": "s9600213",
"date": "2024-01-15"
})
Get route thread information.
Parameters:
params (dict, optional) - Request parameters (uid, etc.)Returns: Thread information dictionary
Example:
thread_info = client.thread(params={"uid": "12345"})
Find nearest stations by coordinates.
Parameters:
params (dict, optional) - Request parameters (lat, lng, distance, etc.)auto_paginate (bool, default: True) - Automatically fetch all pagesresult_key (str, optional, default: "stations") - Key to extract from paginated resultsReturns: List of station information
Example:
stations = client.nearest_stations(params={
"lat": 55.7558,
"lng": 37.6173,
"distance": 50
})
Find nearest settlement by coordinates.
Parameters:
params (dict, optional) - Request parameters (lat, lng, etc.)Returns: Settlement information dictionary
Example:
settlement = client.nearest_settlement(params={
"lat": 55.7558,
"lng": 37.6173
})
Get carrier information.
Parameters:
params (dict, optional) - Request parameters (code, etc.)Returns: Carrier information dictionary
Example:
carrier_info = client.carrier(params={"code": "SU"})
Get list of stations.
Parameters:
params (dict, optional) - Request parametersReturns: List of stations
Example:
stations = client.stations_list()
Get copyright information.
Parameters:
params (dict, optional) - Request parametersReturns: Copyright information dictionary
Example:
copyright_info = client.copyright()
Generic method to call any API endpoint.
Parameters:
endpoint (str) - API endpoint pathparams (dict, optional) - Request parametersauto_paginate (bool, default: False) - Automatically fetch all pagesresult_key (str, optional) - Key to extract from paginated resultsReturns: API response (list if paginated, dict otherwise)
Example:
result = client.get("custom/endpoint", params={"param": "value"})
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!")
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())
Counter for tracking API key usage stored in a JSON file.
from yarasp import JSONUsageCounter
counter = JSONUsageCounter(file_path="yarasp_counter.json")
Methods:
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 the usage counter for today.
Returns: int - Updated count after incrementing
Example:
count = counter.increment()
print(f"Usage count: {count}")
YARASP_API_KEY (required) - API key for Yandex Schedule APIYARASP_API_DAILY_LIMIT (optional, default: 500) - Daily request limitYARASP_SAFE_MODE (optional, default: 1) - Enable safe mode (1 or 0)Raised when:
Raised when trying to use Redis counter backend (not yet implemented).
Raised when unsupported counter backend is specified.
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"})