Skip to main content

Soap client for Here Comes the Bus

Project description

hcb_soap_client

A Python async SOAP client for the "Here Comes the Bus" API, used to track school bus locations and schedules.

Installation

pip install hcb_soap_client

Or install from source:

git clone https://github.com/pcartwright81/hcb_soap_client.git
cd hcb_soap_client
pip install -e .

Usage

Basic Usage (Context Manager - Recommended)

Using the async context manager is the most efficient approach as it reuses the HTTP session across multiple requests:

import asyncio
from hcb_soap_client import HcbSoapClient

async def main():
    async with HcbSoapClient() as client:
        # Get school ID from school code
        school_id = await client.get_school_id("YOUR_SCHOOL_CODE")

        # Login and get parent/account info
        account = await client.get_parent_info(school_id, "username", "password")
        print(f"Account ID: {account.account_id}")
        print(f"Students: {[s.first_name for s in account.students]}")

        # Get bus stop info for a student
        for student in account.students:
            # Use AM_ID for morning routes, PM_ID for afternoon
            stops = await client.get_stop_info(
                school_id,
                account.account_id,
                student.student_id,
                HcbSoapClient.AM_ID  # or HcbSoapClient.PM_ID
            )

            if stops.vehicle_location:
                print(f"Bus location: {stops.vehicle_location.address}")
                print(f"Speed: {stops.vehicle_location.speed} mph")

asyncio.run(main())

Simple Usage (Without Context Manager)

For one-off requests, you can use the client without a context manager. Note that this creates a new HTTP session for each request:

async def simple_example():
    client = HcbSoapClient()
    school_id = await client.get_school_id("YOUR_SCHOOL_CODE")

Using a Custom Session

You can provide your own aiohttp.ClientSession for advanced use cases:

import aiohttp

async def custom_session_example():
    async with aiohttp.ClientSession() as session:
        client = HcbSoapClient(session=session)
        school_id = await client.get_school_id("YOUR_SCHOOL_CODE")

API Reference

HcbSoapClient

Constructor

HcbSoapClient(url: str | None = None, session: aiohttp.ClientSession | None = None)
  • url: Optional custom API endpoint (defaults to production URL)
  • session: Optional aiohttp session to reuse

Class Attributes

  • AM_ID: Time of day ID for morning routes
  • PM_ID: Time of day ID for afternoon routes

Methods

get_school_id(school_code: str) -> str

Look up the school ID from a school code.

get_parent_info(school_id: str, username: str, password: str) -> AccountResponse

Authenticate and retrieve account information including students and time of day options.

get_stop_info(school_id: str, parent_id: str, student_id: str, time_of_day_id: str) -> StopResponse

Get bus stop information and current vehicle location for a student.

Response Models

All response models are Pydantic BaseModel instances.

AccountResponse

  • account_id: str
  • students: list[Student]
  • times: list[TimeOfDay]

Student

  • student_id: str
  • first_name: str
  • last_name: str

StopResponse

  • vehicle_location: VehicleLocation | None
  • student_stops: list[StudentStop]

VehicleLocation

  • name: str - Vehicle/bus name
  • latitude: float
  • longitude: float
  • log_time: datetime
  • speed: int
  • heading: str
  • address: str
  • ignition: bool
  • display_on_map: bool

Development

Install development dependencies

pip install -e ".[dev,test]"

Run tests

pytest

Run linter

ruff check .

License

MIT License - see LICENSE for details.

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

hcb_soap_client-0.1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hcb_soap_client-0.1.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file hcb_soap_client-0.1.1.tar.gz.

File metadata

  • Download URL: hcb_soap_client-0.1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.11

File hashes

Hashes for hcb_soap_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9ec86ea6d20ed7a85ac852bce2b3da37db1b253c6551bd3c941173a094abdcb1
MD5 16b7bedcb76bc78a4deb64d33c4b141e
BLAKE2b-256 df0398719a94942a3cb5b94852818d3c4a23cd7317936aee91ac7ee0309c62fc

See more details on using hashes here.

File details

Details for the file hcb_soap_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hcb_soap_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0ce531ce227f228f2d1edd4c38210f49c327640bd93aaed87d749007736ce89
MD5 20d8aba763351ec50833a89ecd57a1c2
BLAKE2b-256 ccc539c4e578dae0a8311371bb9eb61b3075b3be6cc17ed534326940e1bd4e00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page