API Reference

The following is a API reference of Autobahn generated from Python source code and docstrings.

Warning

This is a complete reference of both the public API and the internal API of Autobahn. Applications should only rely on the public API, since internal APIs can (and often do) change without any guarantees.

Submodules

autobahn.util

autobahn.util.xor(d1, d2)[source]

XOR two binary strings of arbitrary (equal) length.

Parameters:
  • d1 (binary) – The first binary string.
  • d2 (binary) – The second binary string.
Returns:

XOR(d1, d2)

Return type:

binary

autobahn.util.utcstr(ts=None)[source]

Format UTC timestamp in ISO 8601 format.

Note: to parse an ISO 8601 formatted string, use the iso8601 module instead (e.g. iso8601.parse_date("2014-05-23T13:03:44.123Z")).

Parameters:ts (instance of datetime.datetime or None) – The timestamp to format.
Returns:Timestamp formatted in ISO 8601 format.
Return type:unicode
autobahn.util.utcnow()[source]

Get current time in UTC as ISO 8601 string.

Returns:Current time as string in ISO 8601 format.
Return type:unicode
class autobahn.util.IdGenerator[source]

Bases: object

ID generator for WAMP request IDs.

WAMP request IDs are sequential per WAMP session, starting at 1 and wrapping around at 2**53 (both value are inclusive [1, 2**53]).

The upper bound 2**53 is chosen since it is the maximum integer that can be represented as a IEEE double such that all smaller integers are representable as well.

Hence, IDs can be safely used with languages that use IEEE double as their main (or only) number type (JavaScript, Lua, etc).

See https://github.com/wamp-proto/wamp-proto/blob/master/spec/basic.md#ids

next()[source]

Returns next ID.

Returns:The next ID.
Return type:int
autobahn.util.rid()[source]

Generate a new random integer ID from range [0, 2**53].

The generated ID is uniformly distributed over the whole range, doesn’t have a period (no pseudo-random generator is used) and cryptographically strong.

The upper bound 2**53 is chosen since it is the maximum integer that can be represented as a IEEE double such that all smaller integers are representable as well.

Hence, IDs can be safely used with languages that use IEEE double as their main (or only) number type (JavaScript, Lua, etc).

Returns:A random integer ID.
Return type:int
autobahn.util.id()[source]

Generate a new random integer ID from range [0, 2**53].

The generated ID is based on a pseudo-random number generator (Mersenne Twister, which has a period of 2**19937-1). It is NOT cryptographically strong, and hence NOT suitable to generate e.g. secret keys or access tokens.

The upper bound 2**53 is chosen since it is the maximum integer that can be represented as a IEEE double such that all smaller integers are representable as well.

Hence, IDs can be safely used with languages that use IEEE double as their main (or only) number type (JavaScript, Lua, etc).

Returns:A random integer ID.
Return type:int
autobahn.util.newid(length=16)[source]

Generate a new random string ID.

The generated ID is uniformly distributed and cryptographically strong. It is hence usable for things like secret keys and access tokens.

Parameters:length (int) – The length (in chars) of the ID to generate.
Returns:A random string ID.
Return type:unicode
autobahn.util.generate_token(char_groups, chars_per_group, chars=None, sep=None, lower_case=False)[source]

Generate cryptographically strong tokens, which are strings like M6X5-YO5W-T5IK. These can be used e.g. for used-only-once activation tokens or the like.

The returned token has an entropy of:

math.log(len(chars), 2.) * chars_per_group * char_groups

bits. With the default charset and 4 characters per group, rtoken() produces tokens with the following entropy:

character groups entropy (at least) recommended use

2 38 bits 3 57 bits one-time activation or pairing code 4 76 bits secure user password 5 95 bits 6 114 bits globally unique serial / product code 7 133 bits

Here are 3 examples:

  • token(3): 9QXT-UXJW-7R4H
  • token(4): LPNN-JMET-KWEP-YK45
  • token(6): NXW9-74LU-6NUH-VLPV-X6AG-QUE3
Parameters:
  • char_groups (int) – Number of character groups (or characters if chars_per_group == 1).
  • chars_per_group (int) – Number of characters per character group (or 1 to return a token with no grouping).
  • chars (unicode or None) – Characters to choose from. Default is 27 character subset of the ISO basic Latin alphabet (see: DEFAULT_TOKEN_CHARS).
  • sep (unicode) – When separating groups in the token, the separater string.
Returns:

The generated token.

Return type:

unicode

autobahn.util.generate_activation_code()[source]
autobahn.util.generate_user_password()[source]
autobahn.util.generate_serial_number()[source]
autobahn.util.rtime()

Precise wallclock time.

Returns:The current wallclock in seconds. Returned values are only guaranteed to be meaningful relative to each other.
Return type:float
class autobahn.util.Stopwatch(start=True)[source]

Bases: object

Stopwatch based on walltime.

This can be used to do code timing and uses the most precise walltime measurement available on the platform. This is a very light-weight object, so create/dispose is very cheap.

Parameters:start (bool) – If True, immediately start the stopwatch.
elapsed()[source]

Return total time elapsed in seconds during which the stopwatch was running.

Returns:The elapsed time in seconds.
Return type:float
pause()[source]

Pauses the stopwatch and returns total time elapsed in seconds during which the stopwatch was running.

Returns:The elapsed time in seconds.
Return type:float
resume()[source]

Resumes a paused stopwatch and returns total elapsed time in seconds during which the stopwatch was running.

Returns:The elapsed time in seconds.
Return type:float
stop()[source]

Stops the stopwatch and returns total time elapsed in seconds during which the stopwatch was (previously) running.

Returns:The elapsed time in seconds.
Return type:float
class autobahn.util.Tracker(tracker, tracked)[source]

Bases: object

A key-based statistics tracker.

track(key)[source]

Track elapsed for key.

Parameters:key (str) – Key under which to track the timing.
diff(start_key, end_key, formatted=True)[source]

Get elapsed difference between two previously tracked keys.

Parameters:
  • start_key (str) – First key for interval (older timestamp).
  • end_key (str) – Second key for interval (younger timestamp).
  • formatted (bool) – If True, format computed time period and return string.
Returns:

Computed time period in seconds (or formatted string).

Return type:

float or str

absolute(key)[source]

Return the UTC wall-clock time at which a tracked event occurred.

Parameters:key (str) – The key
Returns:Timezone-naive datetime.
Return type:instance of datetime.datetime
class autobahn.util.EqualityMixin[source]

Bases: object

Mixing to add equality comparison operators to a class.

Two objects are identical under this mixin, if and only if:

  1. both object have the same class
  2. all non-private object attributes are equal
class autobahn.util.ObservableMixin[source]

Bases: object

Internal utility for enabling event-listeners on particular objects

set_valid_events(valid_events=None)[source]
Parameters:valid_events – if non-None, .on() or .fire() with an event not listed in valid_events raises an exception.
on(event, handler)[source]

Add a handler for an event.

Parameters:
  • event – the name of the event
  • handler – a callable thats invoked when .fire() is called for this events. Arguments will be whatever are given to .fire()
off(event=None, handler=None)[source]

Stop listening for a single event, or all events.

Parameters:
  • event – if None, remove all listeners. Otherwise, remove listeners for the single named event.
  • handler – if None, remove all handlers for the named event; otherwise remove just the given handler.
fire(event, *args, **kwargs)[source]

Fire a particular event.

Parameters:event – the event to fire. All other args and kwargs are passed on to the handler(s) for the event.
Returns:a Deferred/Future gathering all async results from all handlers and/or parent handlers.

Module contents

Reactive Manifesto: We are reactive banner