mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 12:50:53 +00:00
add defaultkwarg section to readme.
fix callback function names in readme. add logging section to readme
This commit is contained in:
parent
9fa5b3f4b4
commit
aaa881ee3b
51
README.md
51
README.md
@ -12,7 +12,7 @@ Not all endpoints in the official documentation are implemented.
|
|||||||
|
|
||||||
- [OBS Studio](https://obsproject.com/)
|
- [OBS Studio](https://obsproject.com/)
|
||||||
- [OBS Websocket v5 Plugin](https://github.com/obsproject/obs-websocket/releases/tag/5.0.0)
|
- [OBS Websocket v5 Plugin](https://github.com/obsproject/obs-websocket/releases/tag/5.0.0)
|
||||||
- With the release of OBS Studio version 28, Websocket plugin is included by default. But it should be manually installed for earlier versions of OBS.
|
- With the release of OBS Studio version 28, Websocket plugin is included by default. But it should be manually installed for earlier versions of OBS.
|
||||||
- Python 3.10 or greater
|
- Python 3.10 or greater
|
||||||
|
|
||||||
### How to install using pip
|
### How to install using pip
|
||||||
@ -23,7 +23,19 @@ pip install obsws-python
|
|||||||
|
|
||||||
### How to Use
|
### How to Use
|
||||||
|
|
||||||
Load connection info from toml config. A valid `config.toml` might look like this:
|
By default the clients connect with parameters:
|
||||||
|
|
||||||
|
- `host`: "localhost"
|
||||||
|
- `port`: 4455
|
||||||
|
- `password`: None
|
||||||
|
|
||||||
|
You may override these parameters by storing them in a toml config file or passing them as keyword arguments.
|
||||||
|
|
||||||
|
Order of precedence: keyword arguments then config file then default values.
|
||||||
|
|
||||||
|
#### `config file`
|
||||||
|
|
||||||
|
A valid `config.toml` might look like this:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[connection]
|
[connection]
|
||||||
@ -36,12 +48,6 @@ It should be placed next to your `__main__.py` file.
|
|||||||
|
|
||||||
#### Otherwise:
|
#### Otherwise:
|
||||||
|
|
||||||
Import and start using, keyword arguments are as follows:
|
|
||||||
|
|
||||||
- `host`: obs websocket server
|
|
||||||
- `port`: port to access server
|
|
||||||
- `password`: obs websocket server password
|
|
||||||
|
|
||||||
Example `__main__.py`:
|
Example `__main__.py`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -75,7 +81,7 @@ For a full list of requests refer to [Requests](https://github.com/obsproject/ob
|
|||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
When registering a function callback use the name of the expected API event in snake case form.
|
When registering a callback function use the name of the expected API event in snake case form, prepended with "on\_".
|
||||||
|
|
||||||
example:
|
example:
|
||||||
|
|
||||||
@ -83,23 +89,23 @@ example:
|
|||||||
# load conn info from config.toml
|
# load conn info from config.toml
|
||||||
cl = obs.EventClient()
|
cl = obs.EventClient()
|
||||||
|
|
||||||
def scene_created(data):
|
def on_scene_created(data):
|
||||||
...
|
...
|
||||||
|
|
||||||
# SceneCreated
|
# SceneCreated
|
||||||
cl.callback.register(scene_created)
|
cl.callback.register(on_scene_created)
|
||||||
|
|
||||||
def input_mute_state_changed(data):
|
def on_input_mute_state_changed(data):
|
||||||
...
|
...
|
||||||
|
|
||||||
# InputMuteStateChanged
|
# InputMuteStateChanged
|
||||||
cl.callback.register(input_mute_state_changed)
|
cl.callback.register(on_input_mute_state_changed)
|
||||||
|
|
||||||
# returns a list of currently registered events
|
# returns a list of currently registered events
|
||||||
print(cl.callback.get())
|
print(cl.callback.get())
|
||||||
|
|
||||||
# You may also deregister a callback
|
# You may also deregister a callback
|
||||||
cl.callback.deregister(input_mute_state_changed)
|
cl.callback.deregister(on_input_mute_state_changed)
|
||||||
```
|
```
|
||||||
|
|
||||||
`register(fns)` and `deregister(fns)` accept both single functions and lists of functions.
|
`register(fns)` and `deregister(fns)` accept both single functions and lists of functions.
|
||||||
@ -116,7 +122,7 @@ example:
|
|||||||
resp = cl.get_version()
|
resp = cl.get_version()
|
||||||
print(resp.attrs())
|
print(resp.attrs())
|
||||||
|
|
||||||
def scene_created(data):
|
def on_scene_created(data):
|
||||||
print(data.attrs())
|
print(data.attrs())
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -126,6 +132,21 @@ If a request fails an `OBSSDKError` will be raised with a status code.
|
|||||||
|
|
||||||
For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
|
For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
|
||||||
|
|
||||||
|
### Logging
|
||||||
|
|
||||||
|
If you want to see the raw messages simply set log level to DEBUG
|
||||||
|
|
||||||
|
example:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import obsws_python as obs
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
First install development dependencies:
|
First install development dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user