Package: vatsim-api
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).StatusThis 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.InstallationThe easiest way to install is via pip.pip install vatsim-apiAlternatively, you can use thevatsimfolder orliveapi.pyas a package or single-file module, respectively. Make sure you have the necessary 3rd-party libraries installed withpip(at the moment, onlyrequestsis required).Full DocumentationTBDKnown Issues and Noteworthy ConsiderationsTBDExamplesCreate API objectUse default caching periods (60 seconds for METARs and 15 seconds for network data)importvatsimapi=vatsim.VatsimLiveAPI()Create API object with different cache TTLsConfigurable with theDATA_TTLandMETAR_TTLarguments, which speciy how long network data and METAR data should be cached (in seconds), respectivelyimportvatsim# 1 min network data cache and 5 min METAR cacheapi=vatsim_api.VatsimLiveAPI(DATA_TTL=60,METAR_TTL=300)Retrieve all pilots or controllers and iterate through thempilots()returns a dictionary ofPilotinstances with eachPilot.cidas the dictionary keycontrollers()returns a dictionary ofControllerinstances with eachController.cidas the dictionary keyp=api.pilots()forcid,pilotinp.items():# Do something herec=api.controllers()forcid,controllerinc.items():# Do something hereRetrieve a list of pilots  or controllers based on multiple CIDscidsargument expects either a single integer or a list of integers.pilots(cid)returns a dictionary ofPilotinstances based on exact CID matches, orNoneif no matches are foundcontrollers(cid)returns a dictionary ofControllerinstances based on exact CID matches, orNoneif no matches are foundp=api.pilots(cids=[123456,234567,345678])forcid,pilotinp.items():# Do something herec=api.controllers(cids=[123456,234567,345678])forcid,controllerinc.items():# Do something hereRetrieve a list of pilots or controllers based on one or more string regular expressionscallsignsargument expects either a single string or a list of strings.callsignsargument will be ignored ifcidsargument is provided, as in the example above.pilots(callsigns)will evaluate each string as a Python regular expression and return a dictionary ofPilotinstances where the Pilot's callsign matches one of the given callsign regular expressions (usingre.search), orNoneif no matches are foundcontrollers(callsigns)will evaluate each string as a Python regular expression and return a dictionary ofControllerinstances where the Controller's callsign matches one of the given callsign regular expressions (usingre.search), orNoneif no matches are foundp=api.pilots(callsigns=['UAL123','UAL','SWA'])forcid,pilotinp.items():# Do something here# Note that last item uses regex to match OAK_CTR, OAK_41_CTR, OAK_44_CTR, etc. but not OAK_GNDc=api.controllers(callsigns=['SFO','SJC','OAK.*_CTR'])forcid,controllerinc.items():# Do something hereRetrieve a single pilot or controller by Vatsim CID or callsigncidargument expects an integer.callsignargument expects a string. . If bothcidandcallsignarguments are provided, onlycidwill be used.pilot()returns a singlePilotinstance based on exact CID or callsign string match (both are unique on the Vatsim network for Pilots) orNonecontroller()returns a singleControllerinstance based on exact CID or callsign string match (both are unique on the Vatsim network for Controllers) orNonep1=api.pilot(cid=123456)p2=api.pilot(callsign='UAL123')c1=api.controller(cid=123456)c2=api.controller(callsign='SFO_TWR')Retrieve all METARsm=api.metars()forfield,metarinm.items():# Do somethingRetrieve a subset of METARsm=api.metars(['KSFO','KLAX'],['KSJC'])forfield,metarinm.items():# Do somethingRetrieve a single METARm=api.metar('KSFO')Access information about a pilot and their flightplanp=api.pilots()forcid,pilotinp.items():ifpilot.flight_planisnotNone:print('%sdeparted from%sand is going to%sat current altitude%i'%(pilot.callsign,pilot.flight_plan.departure,pilot.flight_plan.arrival,pilot.altitude))else:print('%sis at current altitude%iwith no flight plan'%(pilot.callsign,pilot.altitude))Get information about a controllerc=api.controllers()forcid,controllerinc.items():print('%scontrolling position%son%s'%(controller.name,controller.callsign,controller.frequency))TodoTBDLicenseVatsim Py-API is licensed under the MIT License.