This FastAPI application provides an interface to access real-time satellite data and visualize their positions.
- Retrieves Two-Line Element (TLE) data for satellites using a provided satellite ID and an API key.
- Calculates the current position (longitude, latitude, altitude) of a satellite based on its TLE data.
- Generates a map visualization of the satellite's position on Earth.
- Python 3.x
- FastAPI
requestspython-dotenvskyfieldpandasplotly.expressplotly.io
-
Create a virtual environment (recommended).
-
Install required libraries:
pip install fastapi requests python-dotenv skyfield pandas plotly
-
Create a
.envfile in your project directory with the following line:sat_api_key=YOUR_API_KEYReplace
YOUR_API_KEYwith a valid API key from a satellite data provider like n2yo.com.
-
Start the server:
uvicorn main:app --reload
(Replace
mainwith your main application file name if it's different)
| Endpoint | Description |
|---|---|
/ |
Returns a simple "Hello World!" message |
/satellite/tle/{sat_id} |
Retrieves TLE data for a satellite by its ID |
/satellite/track/{sat_id} |
Calculates and returns the current position of a satellite |
/satellite/visualization/{sat_id} |
Generates and returns an HTML map visualization of the satellite's position |
-
Retrieving TLE Data:
curl http://localhost:8000/satellite/tle/12345 # Replace 12345 with the satellite IDThis will return the TLE data for the satellite in JSON format.
-
Tracking Satellite:
curl http://localhost:8000/satellite/track/12345 # Replace 12345 with the satellite IDThis will return the current position (longitude, latitude, altitude) of the satellite in JSON format.
-
Generating Visualization:
curl http://localhost:8000/satellite/visualization/12345 # Replace 12345 with the satellite IDThis will download an HTML file named
satellites.htmlcontaining a map visualization of the satellite's position. You can open this file in a web browser to view the map.
- This application retrieves TLE data from an external API. You may need to create an account and obtain an API key from the chosen provider.
- The accuracy of the satellite position is based on the TLE data, which can be updated periodically.