SpaceTrackClient handles authentication and HTTP communication with Space-Track.org. It manages session cookies, provides both raw and typed query execution, and automatically authenticates on the first request if needed.
importbraheasbh# Standard clientclient=bh.SpaceTrackClient("user@example.com","password")# Client with custom base URL (e.g., for testing)client=bh.SpaceTrackClient("user@example.com","password",base_url="https://test.space-track.org")
usebrahe::spacetrack::SpaceTrackClient;// Standard clientletclient=SpaceTrackClient::new("user@example.com","password");// Client with custom base URL (e.g., for testing)letclient=SpaceTrackClient::with_base_url("user@example.com","password","https://test.space-track.org");
The client includes a built-in rate limiter that prevents exceeding Space-Track.org's request limits. By default, conservative limits of 25 requests/minute and 250 requests/hour are applied automatically. Pass a RateLimitConfig to customize or disable rate limiting.
The client authenticates lazily -- credentials are sent on the first query. Call authenticate() explicitly to verify credentials before executing queries.
importbraheasbhclient=bh.SpaceTrackClient("user@example.com","password")# Query GP data for the ISSquery=(bh.SpaceTrackQuery(bh.RequestClass.GP).filter("NORAD_CAT_ID","25544").order_by("EPOCH",bh.SortOrder.DESC).limit(1))records=client.query_gp(query)iss=records[0]print(f"Object: {iss.object_name}")print(f"Epoch: {iss.epoch}")print(f"Inclination: {iss.inclination}")# Query SATCAT metadataquery=(bh.SpaceTrackQuery(bh.RequestClass.SATCAT).filter("NORAD_CAT_ID","25544").limit(1))records=client.query_satcat(query)iss_meta=records[0]print(f"Name: {iss_meta.satname}")print(f"Country: {iss_meta.country}")print(f"Launch: {iss_meta.launch}")
usebrahe::spacetrack::{SpaceTrackClient,SpaceTrackQuery,RequestClass,SortOrder};letclient=SpaceTrackClient::new("user@example.com","password");// Query GP data for the ISSletquery=SpaceTrackQuery::new(RequestClass::GP).filter("NORAD_CAT_ID","25544").order_by("EPOCH",SortOrder::Desc).limit(1);letrecords=client.query_gp(&query).unwrap();letiss=&records[0];println!("Object: {:?}",iss.object_name);println!("Epoch: {:?}",iss.epoch);println!("Inclination: {:?}",iss.inclination);// Query SATCAT metadataletquery=SpaceTrackQuery::new(RequestClass::SATCAT).filter("NORAD_CAT_ID","25544").limit(1);letrecords=client.query_satcat(&query).unwrap();letiss_meta=&records[0];println!("Name: {:?}",iss_meta.satname);println!("Country: {:?}",iss_meta.country);println!("Launch: {:?}",iss_meta.launch);
importbraheasbhclient=bh.SpaceTrackClient("user@example.com","password")# Get TLE text directlyquery=(bh.SpaceTrackQuery(bh.RequestClass.GP).filter("NORAD_CAT_ID","25544").format(bh.OutputFormat.TLE).limit(1))tle_text=client.query_raw(query)print(tle_text)# Get raw JSON for flexible processingquery=(bh.SpaceTrackQuery(bh.RequestClass.GP).filter("NORAD_CAT_ID","25544").limit(1))json_data=client.query_json(query)print(json_data[0]["OBJECT_NAME"])
usebrahe::spacetrack::{SpaceTrackClient,SpaceTrackQuery,RequestClass,OutputFormat};letclient=SpaceTrackClient::new("user@example.com","password");// Get TLE text directlyletquery=SpaceTrackQuery::new(RequestClass::GP).filter("NORAD_CAT_ID","25544").format(OutputFormat::TLE).limit(1);lettle_text=client.query_raw(&query).unwrap();println!("{}",tle_text);// Get raw JSON for flexible processingletquery=SpaceTrackQuery::new(RequestClass::GP).filter("NORAD_CAT_ID","25544").limit(1);letjson_data=client.query_json(&query).unwrap();println!("{}",json_data[0]["OBJECT_NAME"]);
The client returns errors for authentication failures, network issues, and format mismatches. In Python, these raise exceptions; in Rust, they return Result<_, BraheError>.
Common error scenarios:
Invalid credentials -- authenticate() or the first query fails
Format mismatch -- Using query_gp() with a non-JSON format set on the query
Network errors -- Connection failures, timeouts
API errors -- Invalid field names, unsupported filter combinations