Library to access Vatsim live data and APIs
Project description
What is Vatsim Py-API?
Vatsim Py-API is a Python library to interact with data from Vatsim's live datafeed, currently located at: http://data.vatsim.net/. It implements Python objects to access the underlying Vatsim data in a Pythonic way, and also parses certain data into developer friendly formats (e.g., timestamp strings into Python datetime objects).
Because Vatsim's datafeed is updated every ~15 seconds, Py-API supports configurable caching of data from the datafeed so that each access method does not fetch the datafeed (although a "force update" override exists if needed).
Status
This project is in alpha state. It currently offers full functionality to access the Vatsim live data (with time-based caching support), but further work is needed in the areas of: documentation, error handling, caching, configurability, testing.
Installation
The easiest way to install is via pip.
pip install vatsim-api
Alternatively, you can use the vatsim folder or liveapi.py as a package or single-file module, respectively. Make sure you have the necessary 3rd-party libraries installed with pip (at the moment, only requests is required).
Full Documentation
TBD
Known Issues and Noteworthy Considerations
TBD
Examples
Create API object
Use default caching periods (60 seconds for METARs and 15 seconds for network data)
import vatsim
api = vatsim.VatsimLiveAPI()
Create API object with different cache TTLs
Configurable with the DATA_TTL and METAR_TTL arguments, which speciy how long network data and METAR data should be cached (in seconds), respectively
import vatsim
# 1 min network data cache and 5 min METAR cache
api = vatsim_api.VatsimLiveAPI(DATA_TTL=60, METAR_TTL=300)
Retrieve all pilots or controllers and iterate through them
pilots() returns a dictionary of Pilot instances with each Pilot.cid as the dictionary key
controllers() returns a dictionary of Controller instances with each Controller.cid as the dictionary key
p = api.pilots()
for cid, pilot in p.items():
# Do something here
c = api.controllers()
for cid, controller in c.items():
# Do something here
Retrieve a list of pilots or controllers based on multiple CIDs
cids argument expects either a single integer or a list of integers.
pilots(cid) returns a dictionary of Pilot instances based on exact CID matches, or None if no matches are found
controllers(cid) returns a dictionary of Controller instances based on exact CID matches, or None if no matches are found
p = api.pilots(cids=[123456, 234567, 345678])
for cid, pilot in p.items():
# Do something here
c = api.controllers(cids=[123456, 234567, 345678])
for cid, controller in c.items():
# Do something here
Retrieve a list of pilots or controllers based on one or more string regular expressions
callsigns argument expects either a single string or a list of strings. callsigns argument will be ignored if cids argument is provided, as in the example above.
pilots(callsigns) will evaluate each string as a Python regular expression and return a dictionary of Pilot instances where the Pilot's callsign matches one of the given callsign regular expressions (using re.search), or None if no matches are found
controllers(callsigns) will evaluate each string as a Python regular expression and return a dictionary of Controller instances where the Controller's callsign matches one of the given callsign regular expressions (using re.search), or None if no matches are found
p = api.pilots(callsigns=['UAL123', 'UAL', 'SWA'])
for cid, pilot in p.items():
# Do something here
# Note that last item uses regex to match OAK_CTR, OAK_41_CTR, OAK_44_CTR, etc. but not OAK_GND
c = api.controllers(callsigns=['SFO', 'SJC', 'OAK.*_CTR'])
for cid, controller in c.items():
# Do something here
Retrieve a single pilot or controller by Vatsim CID or callsign
cid argument expects an integer. callsign argument expects a string. . If both cid and callsign arguments are provided, only cid will be used.
pilot() returns a single Pilot instance based on exact CID or callsign string match (both are unique on the Vatsim network for Pilots) or None
controller() returns a single Controller instance based on exact CID or callsign string match (both are unique on the Vatsim network for Controllers) or None
p1 = api.pilot(cid=123456)
p2 = api.pilot(callsign='UAL123')
c1 = api.controller(cid=123456)
c2 = api.controller(callsign='SFO_TWR')
Retrieve all METARs
m = api.metars()
for field, metar in m.items():
# Do something
Retrieve a subset of METARs
m = api.metars(['KSFO', 'KLAX'], ['KSJC'])
for field, metar in m.items():
# Do something
Retrieve a single METAR
m = api.metar('KSFO')
Access information about a pilot and their flightplan
p = api.pilots()
for cid, pilot in p.items():
if pilot.flight_plan is not None:
print('%s departed from %s and is going to %s at current altitude %i' % (pilot.callsign, pilot.flight_plan.departure, pilot.flight_plan.arrival, pilot.altitude))
else:
print('%s is at current altitude %i with no flight plan' % (pilot.callsign, pilot.altitude))
Get information about a controller
c = api.controllers()
for cid, controller in c.items():
print('%s controlling position %s on %s' % (controller.name, controller.callsign, controller.frequency))
Todo
TBD
License
Vatsim Py-API is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 vatsim_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vatsim_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2a8f45be8de302fd3fecfa11a31d823c979ec375aa0e01f6b21e52aa243f362
|
|
| MD5 |
5bf17fa7e8d05799ad7b40a897387858
|
|
| BLAKE2b-256 |
516c0ec07d3198bf87d020477d7570d75b2cee583180688fc9814e3e2e084dc2
|