messages Module

TypeTags Class

class oscpython.messages.TypeTags(value: Optional[Any] = None, index: int = -1, tags: List[str] = <factory>)[source]

Bases: oscpython.arguments.StringArgument

Container for OSC typetags

tags: List[str]

The list of typetags

append(tag: str)[source]

Append a typetag to the tags list

get_pack_value()Optional[Tuple[bytes]][source]

Get the value(s) to be packed using struct.pack()

Returns None if no value is associated with the argument, otherwise a tuple (even if there is only one item)

classmethod parse(data: bytes)Tuple[oscpython.arguments.StringArgument, bytes][source]

Parse OSC-formatted data and create an Argument

Returns a tuple of:
Argument

Argument containing the parsed value

bytes

Any remaining bytes after the argument data

Packet Class

class oscpython.messages.Packet(remote_client: Optional[oscpython.common.Client] = None, parent_bundle: Optional[oscpython.messages.Bundle] = None, parent_index: Optional[int] = None)[source]

Bases: object

OSC packet (either Message or Bundle)

remote_client: Optional[oscpython.common.Client] = None

If the packet was received, the host that was received from. If sending the packet, the destination host

parent_bundle: Optional[oscpython.messages.Bundle] = None

Instance of Bundle that contains the packet (if any)

parent_index: Optional[int] = None

Index of the packet within the parent_bundle

classmethod parse(packet_data: bytes, **kwargs)Tuple[oscpython.messages.Packet, bytes][source]

Parse OSC-formatted bytes and build a Message or Bundle

Parameters
  • packet_data – The byte string to parse

  • **kwargs – Keyword arguments to pass when creating Packet instances

Returns a tuple of:
Packet

The parsed object

bytes

Any remaining bytes after the packet data

Message Class

class oscpython.messages.Message(remote_client: Optional[oscpython.common.Client] = None, parent_bundle: Optional[oscpython.messages.Bundle] = None, parent_index: Optional[int] = None, address: oscpython.address.Address = <factory>, arguments: List[oscpython.arguments.Argument] = <factory>)[source]

Bases: oscpython.messages.Packet

An OSC Message

address: oscpython.address.Address

The OSC address pattern for the message

arguments: List[oscpython.arguments.Argument]

OSC arguments for the message

property timetag

TimeTag associated with the message

If present, the timetag of the parent_bundle is used. Otherwise, this will always be common.TimeTag.Immediately

classmethod create(address: Union[oscpython.address.Address, str], *args, **kwargs)[source]

Convenience method to create a Message

Creates the address field from the provided address string and adds the message arguments contained in positional args

add_argument(value: Any)oscpython.arguments.Argument[source]

Create an Argument from the given value and add it to the arguments list.

If the value is an instance of Argument it will be added without copying

add_arguments(*values)[source]

Create multiple arguments using add_argument()

build_packet()bytes[source]

Construct a byte string for the message and its arguments

classmethod parse(packet_data: bytes, **kwargs)Tuple[oscpython.messages.Message, bytes][source]

Parse OSC-formatted bytes and build a Message or Bundle

Parameters
  • packet_data – The byte string to parse

  • **kwargs – Keyword arguments to pass when creating Packet instances

Returns a tuple of:
Packet

The parsed object

bytes

Any remaining bytes after the packet data

Bundle Class

class oscpython.messages.Bundle(remote_client: Optional[oscpython.common.Client] = None, parent_bundle: Optional[oscpython.messages.Bundle] = None, parent_index: Optional[int] = None, timetag: oscpython.common.TimeTag = TimeTag(seconds=0, fraction=1), packets: List[oscpython.messages.Packet] = <factory>)[source]

Bases: oscpython.messages.Packet

An OSC Bundle

timetag: oscpython.common.TimeTag = TimeTag(seconds=0, fraction=1)

The TimeTag associated with the bundle

packets: List[oscpython.messages.Packet]

List of Packet instances to include in the bundle. Elements may be either Message or Bundle instances (nested bundles are allowed to occur)

add_packet(packet: oscpython.messages.Packet)[source]

Add a Message or Bundle to the packets list

build_packet()bytes[source]

Construct a byte string for the bundle and the packets it contains

classmethod parse(packet_data: bytes, **kwargs)Tuple[oscpython.messages.Bundle, bytes][source]

Parse OSC-formatted bytes and build a Message or Bundle

Parameters
  • packet_data – The byte string to parse

  • **kwargs – Keyword arguments to pass when creating Packet instances

Returns a tuple of:
Packet

The parsed object

bytes

Any remaining bytes after the packet data

Exceptions

class oscpython.messages.ParseError(packet_data: bytes, msg: Optional[str] = None)[source]

Bases: Exception

class oscpython.messages.PacketStartError(packet_data: bytes, msg: Optional[str] = None)[source]

Bases: oscpython.messages.ParseError

class oscpython.messages.MessageStartError(packet_data: bytes, msg: Optional[str] = None)[source]

Bases: oscpython.messages.PacketStartError

class oscpython.messages.BundleStartError(packet_data: bytes, msg: Optional[str] = None)[source]

Bases: oscpython.messages.PacketStartError