How to Track an Airplane with Python

With all the hype around Jack Sweeny tracking the private jet of billionaire Elon Musk, along with a whole host of other billionaires and celebrities including Bill Gates, Mark Zuckerburg and others. You may very well be wondering how this is possible, well today we will be creating a very simple flight tracker using Python and The Opensky-Network API.

Getting Started

To get started, first you will need a plane to track. In order to do this you will need to obtain the callsign of the aircraft. A callsign is a unique identifier given to each plane that allow us to uniquely identify it. For the sake of this tutorial I will be using the callsign of Elon Musk’s private jet, which we know to be N628TS. Now that we have this, I will input it into the Opensky Network Aircraft Database this will allow us to obtain the Model S hex code of the plane. This is what we will use to get the longitude and latitude of the plane. In this case the hex code is: a835af.

The output received when inputting N628TS into the opensky-network aircraft database
The output received when inputting N628TS into the opensky-network aircraft database

Making requests to the Opensky-Network API

Now that we have the hex code needed, we can start making requests to the Opensky-Nework API. We can do this with the help of the requests module in Python.

Most likely you will get a response that looks something like this

This means that the jet is grounded, if the jet were to be flying the response you get would look something that looks similar to this:

Most of the response you can ignore; for this tutorial the part we are interested in is the 0.7225 and the 49.7943 as these represent the longitude and latitude of the plane. Lets expand the script:

Great! we can now get the longitude and latitude of the plane; as well as a way to detect if the plane is grounded or in the air. The next step is to display the planes route in some meaningful way. For this I will make use of folium to map the longitude and latitude onto a world map:

This code will update the line every 1 minute with the planes new location!

Congrats! You have just build a simple flight tracker with Python!

--

--

Python enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store