Welcome to ursine’s documentation!

ursine is a SIP URI library intended to be easy to integrate into and use for other SIP-focused libraries such as aiosip. In particular its meant to be easy to do the following

  • parse SIP URIs into easy to work with objects
  • generate new SIP URIs
  • normalize the representation of SIP URIs
  • allowing comparisons / hashing of URIs

and do all the same as well for SIP header values with contained URIs.

userinfo and hostport

The SIP spec often refers to the ‘userinfo’ and ‘hostport’ meaning the username+password and hostname+port respectively in a URI. For convenience ursine offers handling the userinfo and hostport either as a single entity or individually. The code below shows this with two effectively identical ways of creating the same URI.

from ursine import URI

uri1 = URI.build(scheme='sip',
                 host='localhost',
                 port=5080,
                 userinfo='john:pass')
uri2 = URI.build(scheme='sip',
                 hostport='localhost:5080',
                 user='john',
                 password='pass')
assert uri1 == uri2

URI

The URI object can be created from a parseable URI in a string, and unspecified attributes will take on reasonable defaults or, where applicable, defaults as specified in the SIP standard.

URIs are treated as immutable, though new URIs can be created from existing ones easily.

from ursine import URI

uri1 = URI('sip:localhost:5080;transport=tcp')
uri2 = URI('sips:localhost:5080')

assert uri1 != uri2
assert uri1 == uri2.with_scheme('sip')
# since URIs are immutable, uri2 is unchanged
assert uri1 != uri2
class ursine.uri.URI(uri: str)

A SIP URI

classmethod build(*, scheme: str, user: Union[str, NoneType] = None, password: Union[str, NoneType] = None, userinfo: Union[str, NoneType] = None, host: Union[str, NoneType] = None, port: Union[int, NoneType] = None, hostport: Union[str, NoneType] = None, parameters: Union[dict, NoneType] = None, headers: Union[multidict._multidict.MultiDict, NoneType] = None, transport: Union[str, NoneType] = None) → ursine.uri.URI

Build a URI from individual pieces.

Both the userinfo and hostport may be broken down into user/password and host/port respectively for convenience, and similarly the transport parameter is offered as an argument for convenience.

short_str()

Get a string representation without parameters/headers.

with_headers(headers: multidict._multidict.MultiDict)

Create a new URI from self with specific headers.

with_host(host: str)

Create a new URI from self with a specific host.

with_hostport(hostport: str)

Create a new URI from self with a specific hostport.

with_parameters(parameters: Dict[str, str])

Create a new URI from self with specific parameters.

with_password(password: Union[str, NoneType])

Create a new URI from self with a specific password.

with_port(port: int)

Create a new URI from self with a specific port.

with_scheme(scheme: str)

Create a new URI from self with a specific scheme.

with_transport(transport: str)

Create a new URI from self with a specific transport.

with_user(user: Union[str, NoneType])

Create a new URI from self with a specific user.

with_userinfo(userinfo: str)

Create a new URI from self with a specific userinfo.

exception ursine.uri.URIError

Indices and tables