Unified Python SDK for Vietnam Transportation (Flight, Train, Bus). Enriched data for RAG & AI Agents.
Project description
TravelSDK for Python
TravelSDK is a high-performance Python library designed to provide a single, consistent interface for searching and managing transportation data across Vietnam. By aggregating data from Vietnam Railways (VNR), dozens of domestic airlines, and hundreds of bus operators, TravelSDK simplifies the complexity of integrating fragmented transportation services into your applications.
1. Project Overview
The primary goal of TravelSDK is to empower developers building travel booking systems, data analysis pipelines, and intelligent AI agents (RAG) with structured, reliable transportation data.
Key Features
- Unified Search Interface: Query trains, buses, and flights using a single method call.
- Hierarchical Location Discovery: Automatically resolves vague location names (e.g., "District 1") to their nearest provincial transportation hubs.
- Built-in Location Database: Includes an offline-first database of over 60 provinces, 160+ train stations, and all domestic airports.
- Strongly Typed Models: Every response is validated using Pydantic, ensuring data integrity and providing full IDE autocompletion support.
- Async-First Architecture: Built on top of
httpxandasynciofor maximum concurrency and performance.
2. Architecture and Design
Location Resolution Engine
TravelSDK implements a dual-layer resolution strategy:
- Local Cache Layer: Checks the built-in
all_locations.jsonfor exact matches or codes (IATA/Station codes). - Dynamic Discovery Layer: If not found locally, the SDK queries the remote API to resolve the area ID and metadata.
Hierarchical Hub Discovery
A unique feature of TravelSDK is its ability to handle "Hub Resolution". If a user searches for a transport hub in a specific district (which typically lacks its own airport or major station), the SDK recursively queries the parent province to identify the actual gateway (e.g., resolving "Hoan Kiem" to "Hanoi Station").
3. Installation
TravelSDK requires Python 3.9 or higher.
Standard Installation
Install the latest stable version from PyPI:
pip install travel-sdk
Development Installation
Install directly from the GitHub repository for the latest features:
pip install git+https://github.com/Qhuy204/TravelSDK.git
For Contributors
Clone the repository and install in editable mode with development dependencies:
git clone https://github.com/Qhuy204/TravelSDK.git
cd TravelSDK
pip install -e ".[dev]"
4. Command Line Interface (CLI)
TravelSDK comes with a powerful CLI tool named travel-sdk (exposed as an entry point).
Basic Usage
# General help
travel-sdk --help
# Unified search across all modes
travel-sdk search --from "Hanoi" --to "Saigon" --date "2026-05-20"
# Specific mode search
travel-sdk search --from "Hai Phong" --to "Nha Trang" --mode flight
# List available resources
travel-sdk list provinces
travel-sdk list airports
travel-sdk list stations
CLI Flags
--verbose: Enables detailed debugging logs for all HTTP requests.--version: Displays the current version of the SDK.
5. Python API Reference
Initialization
The TravelClient is the main entry point. It manages authentication tokens and connection pooling automatically.
from travel import TravelClient
async def main():
async with TravelClient(timeout=30.0, max_retries=3) as client:
# Client handles token rotation and retries internally
pass
Unified Search (search_all)
Runs parallel searches across all available transportation modes and returns a consolidated object.
results = await client.search_all(
from_location="Hanoi",
to_location="Da Nang",
date="2026-05-20",
passengers=1
)
# Accessing specific modes
for train in results.trains:
print(train.train_number)
# Utility methods
print(results.summary()) # Best for LLM consumption
cheapest = results.cheapest()
Dynamic Location Resolution
The SDK exposes methods to manually resolve locations if you aren't performing an immediate search.
# Returns airport metadata including IATA code and internal location ID
airport_info = await client.resolve_flight_airport_async("Noi Bai")
# Returns train station metadata including station code
station_info = await client.resolve_train_station_async("Cau Giay District")
6. Data Schema (Pydantic Models)
TrainTicket
| Field | Type | Description |
|---|---|---|
train_number |
str |
Vehicle identifier (e.g., SE1) |
min_price |
int |
Lowest available seat/sleeper price in VND |
departure_time |
str |
Departure time in HH:MM format |
arrival_time |
str |
Arrival time in HH:MM format |
seat_available |
int |
Total number of seats currently available |
FlightTicket
| Field | Type | Description |
|---|---|---|
airline_name |
str |
Name of the airline carrier |
flight_number |
str |
Carriers flight code (e.g., VJ123) |
final_price |
int |
Total price including taxes and fees |
baggage_info |
str |
Carry-on and checked luggage allowance |
7. Advanced Usage
Handling Token Expiration
TravelClient automatically monitors token TTL. If a 401 Unauthorized response is received, it will transparently refresh the token and retry the request without user intervention.
Logging Configuration
For detailed monitoring, you can enable verbose mode or configure the standard logging library:
import logging
logging.basicConfig(level=logging.DEBUG)
client = TravelClient(verbose=True)
8. Development and Testing
The project uses pytest for all verification tests.
# Run all tests
pytest tests/
# Run specific location resolution tests
python test_hierarchical.py
9. License and Disclaimer
Disclaimer
This is an unofficial SDK and is not affiliated with, endorsed by, or connected to Vexere, VNR (Vietnam Railways), or any specific airline. It utilizes public internal endpoints and is intended for educational and research purposes.
License
This project is licensed under the MIT License.
Copyright (c) 2026 Qhuy204
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file travel_sdk-0.1.2.tar.gz.
File metadata
- Download URL: travel_sdk-0.1.2.tar.gz
- Upload date:
- Size: 40.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d6cb2405eeb60f1d80f44b76ff364858684717a35b5809fc2fc35c3fb958470
|
|
| MD5 |
6cd1d95e4f2e8280654f77824e4cdccb
|
|
| BLAKE2b-256 |
1f21fa86dcde6349edefcf0c5d2fc858a9c5d31b4525ee6789204f5986ed72df
|
Provenance
The following attestation bundles were made for travel_sdk-0.1.2.tar.gz:
Publisher:
workflow.yml on Qhuy204/TravelSDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
travel_sdk-0.1.2.tar.gz -
Subject digest:
3d6cb2405eeb60f1d80f44b76ff364858684717a35b5809fc2fc35c3fb958470 - Sigstore transparency entry: 1340096153
- Sigstore integration time:
-
Permalink:
Qhuy204/TravelSDK@35b7027c92567bd26dafeb40b74ba2d0e8653108 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Qhuy204
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@35b7027c92567bd26dafeb40b74ba2d0e8653108 -
Trigger Event:
push
-
Statement type:
File details
Details for the file travel_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: travel_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 38.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c07038a4e18d5dfc09ba442654a9d84318c84524883f7246006220c970b1d5b6
|
|
| MD5 |
a37e24fb39117db062575ff283bae056
|
|
| BLAKE2b-256 |
54bb3f2678df99f96d43eaf678950feb2cc46c6b89e7db99ab7ff3edfa86c8f3
|
Provenance
The following attestation bundles were made for travel_sdk-0.1.2-py3-none-any.whl:
Publisher:
workflow.yml on Qhuy204/TravelSDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
travel_sdk-0.1.2-py3-none-any.whl -
Subject digest:
c07038a4e18d5dfc09ba442654a9d84318c84524883f7246006220c970b1d5b6 - Sigstore transparency entry: 1340096155
- Sigstore integration time:
-
Permalink:
Qhuy204/TravelSDK@35b7027c92567bd26dafeb40b74ba2d0e8653108 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Qhuy204
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@35b7027c92567bd26dafeb40b74ba2d0e8653108 -
Trigger Event:
push
-
Statement type: