You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor Topic iterator to yield values directly instead of futures, fixing the unbound queue variable bug. Add cancelPayload support to startTopic and simplify subscribeToProperty, subscribeToEvent, and subscribeToLogMessages to use it. Add __aiter__/__anext__/next() to Topic for cleaner `async for` and `await topic.next()` usage. Add type annotations and improve docstrings throughout api.py, topic.py, and socketwrapper.py.
Python library to interface with [OpenSpace](https://github.com/OpenSpace/OpenSpace) using sockets.
2
+
Python library to interface with [OpenSpace](https://github.com/OpenSpace/OpenSpace) using TCP sockets.
3
3
4
-
## Work in progress
5
-
Both the API and library are still very much a work in progress and are subject to change.
4
+
**Work in progress** - Both the API and library are still under active development and are subject to change.
6
5
7
6
## Install
8
-
Stable release of the OpenSpace API Python package are registered at [PyPi](https://pypi.org/project/openspace-api/). The latest version can be installed using `pip`:
7
+
Stable releases are published on [PyPI](https://pypi.org/project/openspace-api/). Install the latest version with:
9
8
10
-
`pip install openspace-api`
9
+
```sh
10
+
pip install openspace-api
11
+
```
11
12
12
-
## Python in the terminal
13
-
https://github.com/OpenSpace/openspace-api-python/blob/master/example/example.py provides an example of how to connect from a Python script using sockets. To run it, run `python example.py` from the working directory in the terminal.
13
+
## Quick start
14
+
15
+
```python
16
+
import asyncio
17
+
import openspace as OpenSpace
18
+
19
+
api = OpenSpace.Api('localhost', 4681)
20
+
disconnect = asyncio.Event()
21
+
22
+
asyncdefonConnect():
23
+
openspace =await api.library()
24
+
time =await openspace.time.UTC()
25
+
print(f"Current simulation time: {time}")
26
+
disconnect.set()
27
+
28
+
defonDisconnect():
29
+
disconnect.set()
30
+
31
+
api.onConnect(onConnect)
32
+
api.onDisconnect(onDisconnect)
33
+
34
+
asyncdefmain():
35
+
await api.connect()
36
+
await disconnect.wait()
37
+
38
+
asyncio.run(main())
39
+
```
40
+
41
+
## Examples
42
+
43
+
Install the example dependencies first:
44
+
45
+
```sh
46
+
pip install -r example/requirements.txt
47
+
```
48
+
49
+
-[example.py](https://github.com/OpenSpace/openspace-api-python/blob/master/example/example.py) - Async script demonstrating get/set property, property subscriptions, event subscriptions, calling Lua library functions, and adding scene graph nodes. Run with:
50
+
```sh
51
+
python example/example.py
52
+
```
53
+
-[example/sync-example.py](https://github.com/OpenSpace/openspace-api-python/blob/master/example/sync-example.py) - Shows how to wrap async API calls to make them synchronous, useful in interactive shells (Python REPL, IPython).
54
+
-[example/notebook-examples.py](https://github.com/OpenSpace/openspace-api-python/blob/master/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.
55
+
56
+
## Requirements
57
+
- Python 3.10+
58
+
- A running instance of [OpenSpace](https://github.com/OpenSpace/OpenSpace)
0 commit comments