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.
Stable releases are published on PyPI. Install the latest version with:
pip install openspace-apiimport 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())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.
- Python 3.10+
- A running instance of OpenSpace