TL;DR
NextBus provides real-time public transit arrival predictions for hundreds of transit agencies across North America and beyond. The API serves XML feeds with vehicle locations, stop lists, route configurations, and arrival time predictions. Supports multiple agencies including Muni (San Francisco), Metro (Los Angeles), and many smaller municipal transit systems. No API key required.
Quick start: http://webservices.nextbus.com/service/publicXMLFeed?command=agencyList
No API key needed — free transit predictions!
How to Use This API
1. List All Transit Agencies
Get a list of all transit agencies available through NextBus:
http://webservices.nextbus.com/service/publicXMLFeed?command=agencyList
2. List Routes for an Agency
Get all routes for SF Muni:
http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=sf-muni
3. Get Predictions for a Stop
Get arrival predictions for a specific route and stop:
http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=N&s=6997
4. JavaScript — Parse Predictions
fetch('http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=N&s=6997')
.then(r => r.text())
.then(xml => {
const parser = new DOMParser();
const doc = parser.parseFromString(xml, 'text/xml');
const predictions = doc.querySelectorAll('prediction');
predictions.forEach(p => {
console.log(`${p.getAttribute('minutes')} min — ${p.getAttribute('vehicle')}`);
});
});
5. Python — Get Vehicle Locations
import requests, xml.etree.ElementTree as ET
resp = requests.get(
'http://webservices.nextbus.com/service/publicXMLFeed',
params={'command': 'vehicleLocations', 'a': 'sf-muni', 't': '0'}
)
root = ET.fromstring(resp.text)
for vehicle in root.findall('.//vehicle'):
print(f"Vehicle {vehicle.get('id')}: "
f"Lat {vehicle.get('lat')}, Lon {vehicle.get('lon')}, "
f"Heading {vehicle.get('heading')}")
http://webservices.nextbus.com/service/publicXMLFeed?command=agencyList
Frequently Asked Questions
- Which transit agencies are supported?
- NextBus supports hundreds of agencies worldwide, primarily in the US and Canada. Major agencies include SF Muni, LA Metro, Seattle King County Metro, and Toronto TTC. Use the
agencyListcommand for the full list. - What commands are available?
- Core commands:
agencyList,routeList,stopList,predictions,vehicleLocations, andschedule. Each takes ana(agency) parameter and route/stop parameters as needed. - Is XML the only output format?
- Yes — NextBus returns XML only. You'll need to parse it client-side with DOMParser (browser) or xml.etree.ElementTree (Python). JSON conversion can be done with middleware if needed.
- How do I find a stop ID?
- Use the
routeConfigcommand to get the full route configuration including all stops with their IDs. For example:command=routeConfig&a=sf-muni&r=N. - Is there a rate limit?
- NextBus does not publish strict rate limits, but requests should be limited to what's needed for real-time displays. Caching predictions for 30-60 seconds is recommended practice.
- Can I get schedule data?
- Yes — the
schedulecommand returns scheduled (not real-time) departure times for any route and stop combination. Useful for baseline comparison with live predictions.
API Details
- API URL
http://webservices.nextbus.com/service/publicXMLFeed- Documentation
- NextBus XML Feed Documentation (PDF)
- Category
- Transportation
- Authentication
- Not Required
- Output Format
- XML
What You Can Build
- Real-time bus arrival display for office lobbies or transit hubs
- Mobile transit app with multi-agency route planning
- Vehicle tracking dashboard showing fleet positions on a map
- Transit reliability analyzer comparing scheduled vs actual arrivals
- Smart display showing next departures at a specific stop