New Satnogs-API-Client (Python+Rust) published

Hello there,

today, I finally published the package satnogs-api-client on pypi and crates.io. satnogs-api-client aims to provide a convenient rusty and pythonic abstraction of the satnogs-netwok API. It is OpenSource and licensed under AGPL-3.0-only.

Motivation

This client is mainly a byproduct of my still ongoing effort to reimplement the satnogs-client in Rust (with some other architectural decisions and more hackable), which lead me to implement this tiny api client too. It encapsulates most of the functionality a satnogs-client needs. This includes also the upload of artifacts (which needed a tiny bit of research).

Once the rust-implementation was there, I felt there should be a python-interface using the maturin crate too. So the functions implemented in this client are also usable from a python-interpreter. I like this combination pretty much for that Python is very elegant and simple in usage, while Rust provides type safety and performance for heavy lifting.

Examples for Python

You can install the package from pypi:

$ pip install satnogs-api-client

and run different examples. This one fetches a specific observation and prints different information on it:

from satnogs_api_client import APIClient

c = APIClient("https://network.satnogs.org/api")

ob = c.get_observation(13341257)

print("ID:     ", ob.id)
print("GS:     ", ob.ground_station)
print("Status: ", ob.status)
print("Packets:", len(ob.demoddata))
print("TLE:    ", ob.tle0)
print("TLE:    ", ob.tle1)
print("TLE:    ", ob.tle2)

gives:

ID:      13341257
GS:      1860
Status:  good
Packets: 1066
TLE:     0 CROCUBE
TLE:     1 62394U 24247T   26036.99781543  .00044088  00000-0  11195-2 0  9999
TLE:     2 62394  44.9735 273.7889 0002212 191.4907 168.5929 15.39013829 63077

With the power of python scripting, also other stuff is possible. E.g. this example deletes future observations scheduled by a specific user (should be used against abuse only!):

from datetime import UTC, datetime
from time import sleep

from satnogs_api_client import APIClient, ObservationFilter


token = "__my_api_token__"
api = APIClient("https://network.satnogs.org/api", token)

f = ObservationFilter(ground_station=2519, end__gt=datetime.now(tz=UTC))

jobs = api.get_observations(f)

for j in jobs:
    if j.observer == "some_user_name":
        print(f"deleting {j.id}...")
        api.delete_job(j.id)
        sleep(1)  # throttling for API

Feel free to hack your own scripts with this. :slight_smile:

Examples for Rust

You can get this crate from crates.io and codeberg.org:

$ cargo add satnogs_api_client

You can find different examples in the examples-folder.
This example lists all stations currently online:

use std::time::Duration;
use ureq::Agent;

use satnogs_api_client::api_client::APIClient;
use satnogs_api_client::filters::StationFilter;

static SATNOGS_NETWORK_URL: &str = "https://network.satnogs.org/api/";

fn main() {
    let config = Agent::config_builder()
        .timeout_global(Some(Duration::from_secs(60)));

    let api = APIClient::new(config, SATNOGS_NETWORK_URL.to_string(), None);

    let f = StationFilter{ status: Some("online".to_string()), name: None, client_version: None };
    let stations = api.get_stations(f).unwrap();

    println!("{} stations online.\n", stations.len());
    for s in stations {
        println!("{}\t{}", s.id, s.name)
    }
}

gives:

306 stations online.

26      SV1IYO/A
34      M0SZT
37      DL4PD
39      CGBSAT-VHF
40      CGBSAT-UHF
77      N5CNB-VHF
85      Alfeld
91      M0EYT
98      Grove-UHF-01
106     BEEGND-1
158     VK6SAT - UHF
167     G7ODQ-pi
168     SM0IFP

I hope you can enjoy this as much as I do. I will take this crate as a foundation of commencing my
satnogs-journey with more rust code.

Best wishes to you all,
mhuebner

6 Likes

thank you. that delete future observations is usefull

This is great! I wrote a tiny API client in Rust a while ago, but would prefer to use an existing crate. Are you planning to support async?

Thank you. :slight_smile:

Currently, I don’t plan on adding async-support, as I would like to keep things small and avoid tokio as a hard dependency. A clean and simple API is important to me. I’m open to suggestions, though. If you have an Idea how to achieve async without depending on tokio, I’d happily accept your contribution. :+1:

Besides that, the API-Limits for satnogs are currently very low (only about some requests per hour). Probably, there is no performance benefit in async-support.

Understandable.

I don’t think you can get async without adding a runtime like tokio. The library that does the HTTP requests needs some async network layer after all, and that is usually provided by the runtime. You can configure tokio to only use the features you need, but I don’t know how “heavy” it still is then.

It’s not so much for performance. I just prefer async because you can do other stuff while waiting for requests without having to use threads. And even if most usecases don’t need it, it just composes better with the rest of an async code-base.

Buf if you don’t want to add it, I’m fine with it. I’ll continue to use my own implementation. I don’t have use for uploading, and only need to fetch few simple endpoints, so it’s not a big deal.