Package: obswsrc

Submodules

obswsrc.client module

exception obswsrc.client.AuthError[source]

Bases: Exception

Raised by OBSWS.connect() if authentication has failed.

class obswsrc.client.OBSWS(host, port=4444, password=None, *, skip_auth=False, loop=None)[source]

Bases: object

Main class used for obs-websocket communication. Can be used as a context manager (given you use it in async with statement).

Example usage:

async with OBSWS("localhost") as obsws:
    ...

This is an equivalent to the following:

obsws = OBSWS("localhost")
await obsws.connect()

try:
    ...
finally:
    await obsws.close()

This class also supports Future-like protocol (it implements __await__() method). You can await for the OBSWS instance for it to close:

await obsws

Note

When entering the context manager (using async with statement), you should be ready to except AuthError that might raise due to failed auth, or OSError that can be raised by the underlying websockets library in case of being unable to connect to OBS Studio.

See also

connect() close()

Parameters:
  • host (str) – Server host
  • port (int) – Server port
  • password (str|None) – Server password (if needed)
  • skip_auth (bool) – Whether or not to skip authentication
  • loop (asyncio.AbstractEventLoop|None) – Event loop to use
close()[source]

Clean shutdown. Consequent calls on an already closed instance have not effect.

Note

This method is a coroutine.

closed

Return whether or not this OBSWS instance is closed.

connect()[source]

Establish connection to the server, start the event loop and perform authentication (the latter can be skipped with skip_auth argument in __init__()).

Raises:
  • ValueError – if already connected
  • AuthError – if auth is enabled but password is invalid or not not set
  • OSError – raised by the underlying websockets library if connection attempt is failed

Note

This method is a coroutine.

event(type_name=None)[source]

Return a future that, when awaited for, returns an event of type type_name. If type_name is None, the future result will be the first occurred event. If connection is closed while future is not done, the future result is None.

Parameters:type_name (str|None) – Event type to await for, None to await for an event of any type
Returns:Future
Return type:asyncio.Future
Raises:ValueError – if not connected

Changed in version 2.3.0: This method is not a coroutine now, but it returns a asyncio.Future object.

host

The host that OBSWS was instantiated with (read-only).

Returns:Server host
Return type:str
password

The port that OBSWS was instantiated with (read-only).

Returns:Server password (None if not given)
Return type:str|None
port

The port that OBSWS was instantiated with (read-only).

Returns:Server port
Return type:int
register_event_handler(type_name, callback)[source]

Register event handler (either a regular one or an async-coroutine).

Parameters:
  • type_name – Event name
  • callback (callable) – Function or coroutine function
Raises:

ValueError – if callback is already registered for the event

Deprecated since version 2.2: Use event() instead.

require(request)[source]

Send a request to the server and await, return the response.

Parameters:request (requests.BaseRequest) – Fully formed request
Returns:Response from the server (None if the connection was closed during communication)
Return type:requests.BaseResponse|None
Raises:ValueError – if not connected

Note

This method is a coroutine.

unregister_event_handler(type_name, callback)[source]

Unregister previously registered event handler.

Parameters:
  • type_name – Event name
  • callback (callable) – Function or coroutine function

Deprecated since version 2.2: Use event() instead.

obswsrc.events module

This module holds dynamically generated classes. For more info see protocol.py and protocol.json.

class obswsrc.events.BaseEvent(*args, **kwargs)[source]

Bases: obswsrc.struct.Struct

type_name
class obswsrc.events.BaseEventMeta(name, bases, namespace)[source]

Bases: obswsrc.struct.StructMeta

obswsrc.protocol module

exception obswsrc.protocol.UnknownType[source]

Bases: Exception

obswsrc.protocol.build_events(protocol, known_types)[source]
obswsrc.protocol.build_requests(protocol, known_types)[source]
obswsrc.protocol.build_types(protocol)[source]

obswsrc.requests module

This module holds dynamically generated classes. For more info see protocol.py and protocol.json.

class obswsrc.requests.BaseRequest(*args, **kwargs)[source]

Bases: obswsrc.struct.Struct

get_request_data(message_id)[source]
class response_class(*args, **kwargs)[source]

Bases: obswsrc.requests.BaseResponse

BaseRequest.type_name
class obswsrc.requests.BaseResponse(*args, **kwargs)[source]

Bases: obswsrc.struct.Struct

class obswsrc.requests.BaseResponseMeta(name, bases, namespace)[source]

Bases: obswsrc.struct.StructMeta

class obswsrc.requests.ResponseStatus[source]

Bases: enum.Enum

An enumeration.

ERROR = 'ERROR'
OK = 'OK'
obswsrc.requests.dummy_request(**kwargs)[source]

obswsrc.struct module

class obswsrc.struct.BaseStruct[source]

Bases: dict

class obswsrc.struct.Struct(*args, **kwargs)[source]

Bases: obswsrc.struct.BaseStruct

class obswsrc.struct.StructField(attr_name, field_name, value_type, optional=False)[source]

Bases: object

class obswsrc.struct.StructMeta(name, bases, namespace)[source]

Bases: type

class obswsrc.struct.VariableStruct(**kwargs)[source]

Bases: obswsrc.struct.BaseStruct

obswsrc.types module

This module holds dynamically generated classes. For more info see protocol.py and protocol.json.