Skip to main content

Python library to interface with OpenSpace using sockets

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openspace_api-0.9.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openspace_api-0.9.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file openspace_api-0.9.1.tar.gz.

File metadata

  • Download URL: openspace_api-0.9.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for openspace_api-0.9.1.tar.gz
Algorithm Hash digest
SHA256 2c0e93c99878feb7e65e7bd10aafa546ad1d28a5935f92e4ecbf0f3bf69b380a
MD5 a64a92ad6db807367743fe97317d42e3
BLAKE2b-256 19d9ccfc4ff0435c806b8fff17b71e51f4d8cdb1386713a669b29ddab80844b4

See more details on using hashes here.

File details

Details for the file openspace_api-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: openspace_api-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for openspace_api-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3f187e527fac1fd7e430114e57f60e551a9f589b39e4d65f4f49e987b24397b
MD5 6e7828a6404003252c6a354396089ae0
BLAKE2b-256 8cbadef5cbb3646eefa093f4457a4c91f549611a9ab3aecd004878d3ee30f804

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page