Skip to content

OpenSpace/openspace-api-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openspace-api-python

Python library to interface with OpenSpace using TCP sockets.

Work in progress - Both the API and library are still under active development and are subject to change.

Install

Stable releases are published on PyPI. Install the latest version with:

pip install openspace-api

Quick start

import asyncio
import openspace as OpenSpace

api = OpenSpace.Api('localhost', 4681)
disconnect = asyncio.Event()

async def onConnect():
  openspace = await api.library()
  time = await openspace.time.UTC()
  print(f"Current simulation time: {time}")
  disconnect.set()

def onDisconnect():
  disconnect.set()

api.onConnect(onConnect)
api.onDisconnect(onDisconnect)

async def main():
  await api.connect()
  await disconnect.wait()

asyncio.run(main())

Examples

Install the example dependencies first:

pip install -r example/requirements.txt
  • example.py - Async script demonstrating get/set property, property subscriptions, event subscriptions, calling Lua library functions, and adding scene graph nodes. Run with:
python example/example.py
  • example/sync-example.py - Shows how to wrap async API calls to make them synchronous, useful in interactive shells (Python REPL, IPython). Run with:
python example/sync-example.py
  • example/notebook-examples.py - Self-contained async functions designed for Jupyter notebooks (await functionName()) or scripts (asyncio.run(functionName())). Covers pausing simulation, navigating to geo coordinates, setting time, and adding globe layers.

Requirements

  • Python 3.10+
  • A running instance of OpenSpace

About

OpenSpace Socket API bindings for Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages