A python client to interact with the Sedaro Satellite API.
Project description
Sedaro Python Client (Beta)
A python client for interacting with the Sedaro Satellite API using intuitive classes and methods.
This client is intended to be used alongside our redocs OpenAPI Specification. Please refer to this documentation for detailed information on the names, attributes, and relationships of each Sedaro Block.
Install
pip install sedaro
Use: Block CRUD
-
Instantiate the
SedaroApiClient
as a context manager. All code interacting with the API should be within the scope of that context manager. Generate an API key in the Sedaro Satellite Management Console.from sedaro import SedaroApiClient API_KEY = 'my_api_key' # Generated in Sedaro Satellite Management Console AGENT_TEMPLATE_BRANCH_ID = 1 # id of a Branch owned by my Sedaro account with the given api key with SedaroApiClient(api_key=API_KEY) as sedaro_client: ...
# If using a dedicated enterprise Sedaro instance, overwrite the default `host` kwarg. ... HOST = 'url-to-my-sedaro-server-instance.com' with SedaroApiClient(api_key=API_KEY, host=HOST) as sedaro_client: ...
-
Use the client to instantiate a
BranchClient
.... with SedaroApiClient(api_key=API_KEY) as sedaro_client: branch_client = sedaro_client.get_branch(AGENT_TEMPLATE_BRANCH_ID)
-
Use the
BranchClient
to access and utilizeBlockClassClient
s. ABlockClassClient
is used to create and access Sedaro Blocks of the respective class.... branch_client = sedaro_client.get_branch(AGENT_TEMPLATE_BRANCH_ID) branch_client.Target tranch_client.Component branch_client.Subsystem # ...etc.
-
Valid
BlockClassClient
s for an Agent Template Branch are as follows:- AngularVelocitySensor
- AveragingAlgorithm
- Battery
- BatteryCell
- BatteryPack
- BodyFrameVector
- BusRegulator
- CelestialTarget
- CelestialVector
- CircularFieldOfView
- Component
- Condition
- ConOps
- ConstantLoad
- Cooler
- DirectionSensor
- EkfAlgorithm
- FovConstraint
- GpsAlgorithm
- GroundTarget
- GroupCondition
- Heater
- LoadState
- LocalVector
- LockPointingMode
- Magnetorquer
- MaxAlignPointingMode
- MekfAlgorithm
- OperationalMode
- OpticalAttitudeSensor
- PassivePointingMode
- PidAlgorithm
- PositionSensor
- ReactionWheel
- RectangularFieldOfView
- Satellite
- SlidingModeAlgorithm
- SolarArray
- SolarCell
- SolarPanel
- SpaceTarget
- Subsystem
- Surface
- SurfaceMaterial
- TargetGroup
- TargetGroupVector
- TargetVector
- TempControllerState
- ThermalInterface
- ThermalInterfaceMaterial
- Topology
- TriadAlgorithm
- VectorSensor
-
Valid
BlockClassClient
s for an Scenario Branch are as follows:- Agent
- ClockConfig
- Orbit
-
-
A
BlockClassClient
has several methods:... branch_client.Subsystem.create( name='Structure', satellite='3' # The ID of the related Satellite Block ) branch_client.Subsystem.get(blockId) # ID of desired Subsystem branch_client.Subsystem.get_all() branch_client.Subsystem.get_first() branch_client.Subsystem.get_last() branch_client.Subsystem.get_all_ids()
-
Most
BlockClassClient
methods return aBlockClient
which has several methods and properties.... subsystem_client = branch_client.Subsystem.create( name='Structure', satellite='3' ) subsystem_client.update(name='Structure 2.0') subsystem_client.delete()
... # A `BlockClient` will always be equal to and in sync with all other `BlockClient`s referencing the same Sedaro Block: subsystem_client = branch_client.Subsystem.create( name='Structure', satellite='3' ) subsystem_client_2 = subsystem_client.update( name='Structure 2.0' ) subsystem_client_3 = branch_client.Subsystem.get(subsystem_client.id) assert subsystem_client == subsystem_client_2 == subsystem_client_3
... # Printing a `BlockClient` will show you the corresponding Sedaro Block's data: print(subsystem_client) >>> Subsystem( >>> id=27 >>> name=Structure 2.0 >>> category=CUSTOM >>> satellite=3 >>> components=() >>> )
# Keying into any property existing on the corresponding Sedaro Block will return that properties value. subsystem_client.name >>> 'Structure 2.0' # Keying into a property that is a relationship field, will return a `BlockClient` corresponding to the related `Block` (or `list` of `BlockClient`s if it's a many-side relationship field). subsystem.satellite >>> Satellite( >>> id=3 >>> mass=1000 >>> ...etc >>> )
# This allows for traversing Blocks in the model via relationship fields: solar_panel_client = branch_client.SolarPanel.get_first() solar_panel_client.cell.panels[-1].subsystem.satellite.components[0].delete()
Full Example
from sedaro import SedaroApiClient
from sedaro.exceptions import NonexistantBlockError
API_KEY = 'my_api_key_generated_by_sedaro_satellite'
AGENT_TEMPLATE_BRANCH_ID = 1
with SedaroApiClient(api_key=API_KEY) as sedaro_client:
branch_client = sedaro_client.get_branch(AGENT_TEMPLATE_BRANCH_ID)
battery_cell_client = branch_client.BatteryCell.create(
partNumber='987654321',
manufacturer='Sedaro Corporation',
esr=0.01,
maxChargeCurrent=15,
maxDischargeCurrent=100,
minSoc=0.2,
capacity=500,
curve=[[0, 0.5, 1], [12.2, 14.1, 16.8]],
topology='5',
)
bc_id = battery_cell_client.id
battery_cell_client.update(partNumber="123456789")
battery_cell_client.delete()
try:
battery_cell_client.update(partNumber="987654321")
except NonexistantBlockError as e:
assert str(e) == f'The referenced "BatteryCell" (id: {bc_id}) no longer exists.'
Use: Simulation
SCENARIO_BRANCH_ID = 2
with SedaroApiClient(api_key=API_KEY) as sedaro_client:
# Instantiate sim client
sim_client = sedaro_client.get_sim_client(SCENARIO_BRANCH_ID)
# Start simulation
sim_client.start()
# Get simulation
response = sim_client.get_latest()
# Check status & percentage complete
job = response.body[0]
assert job['status'] == 'RUNNING'
print(job['progress']['percentComplete'])
# Terminate simulation
response = sim_client.terminate(job['id'])
assert response.body['message'] == 'Successfully terminated simulation.'
Use: Send Requests
Use built-in method to send customized requests to the host. See OpenAPI Specification for documentation on resource paths and body params.
with SedaroApiClient(api_key=API_KEY) as sedaro_client:
# get a branch
sedaro_client.send_request(
f'/models/branches/{WILDFIRE_A_T_ID}',
'GET'
)
# create a celestial target in a branch
sedaro_client.send_request(
f'/models/branches/{WILDFIRE_A_T_ID}/cdh/conops/celestial-targets/',
'POST',
body={
'name': 'Sun',
'polynomialEphemerisBody': 'SUN',
'conOps': 2
}
)
Further information
See docstrings on classes and their methods for further instructions and explanations.
Sedaro Base Client
The Sedaro client is a wrapper around the Swagger generated OpenAPI client. When this package is installed, the auto-generated, lower-loevel clients and methods are also available under sedaro_base_client
.
from sedaro_base_client import ...
Community, Support, Discussion
If you have any issues using the package or any suggestions, please start by reaching out:
- Open an issue on GitHub
- Join the Sedaro Community Slack
- Email us at support@sedarotech.com
Please note that while emails are always welcome, we prefer the first two options as this allows for others to benefit from the discourse in the threads. That said, if the matter is specific to your use case or sensitive in nature, don't hesitate to shoot us an email instead.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.