mautrix.client.api.types package

Submodules

mautrix.client.api.types.filter module

class mautrix.client.api.types.filter.EventFilter(limit: int = None, not_senders: List[NewType.<locals>.new_type] = None, not_types: List[mautrix.client.api.types.event.base.EventType] = None, senders: List[NewType.<locals>.new_type] = None, types: List[mautrix.client.api.types.event.base.EventType] = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

limit = None
not_senders = None
not_types = None
senders = None
types = None
class mautrix.client.api.types.filter.Filter(event_fields: List[str] = None, event_format: <unknown>.EventFormat = None, presence: mautrix.client.api.types.filter.EventFilter = None, account_data: mautrix.client.api.types.filter.EventFilter = None, room: mautrix.client.api.types.filter.RoomFilter = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

account_data = None
event_fields = None
event_format = None
presence = None
room = None
class mautrix.client.api.types.filter.RoomEventFilter(limit: int = None, not_senders: List[NewType.<locals>.new_type] = None, not_types: List[mautrix.client.api.types.event.base.EventType] = None, senders: List[NewType.<locals>.new_type] = None, types: List[mautrix.client.api.types.event.base.EventType] = None, not_rooms: List[NewType.<locals>.new_type] = None, rooms: List[NewType.<locals>.new_type] = None, contains_url: bool = None)[source]

Bases: mautrix.client.api.types.filter.EventFilter, mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

contains_url = None
not_rooms = None
rooms = None
class mautrix.client.api.types.filter.RoomFilter(not_rooms: List[NewType.<locals>.new_type] = None, rooms: List[NewType.<locals>.new_type] = None, ephemeral: mautrix.client.api.types.filter.RoomEventFilter = None, include_leave: bool = False, state: mautrix.client.api.types.filter.RoomEventFilter = None, timeline: mautrix.client.api.types.filter.RoomEventFilter = None, account_data: mautrix.client.api.types.filter.RoomEventFilter = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

account_data = None
ephemeral = None
not_rooms = None
rooms = None
state = None
timeline = None
mautrix.client.api.types.filter.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=True, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False)

A class decorator that adds dunder-methods according to the specified attributes using attr.ib() or the these argument.

Parameters:
  • these (dict of str to attr.ib()) –

    A dictionary of name to attr.ib() mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add __repr__ methods to Django models) or don’t want to.

    If these is not None, attrs will not search the class body for attributes and will not remove any attributes from it.

    If these is an ordered dict (dict on Python 3.6+, collections.OrderedDict otherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.

  • repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful repr output.
  • repr (bool) – Create a __repr__ method with a human readable representation of attrs attributes..
  • str (bool) – Create a __str__ method that is identical to __repr__. This is usually not necessary except for Exceptions.
  • cmp (bool) – Create __eq__, __ne__, __lt__, __le__, __gt__, and __ge__ methods that compare the class as if it were a tuple of its attrs attributes. But the attributes are only compared, if the types of both classes are identical!
  • hash (bool or None) –

    If None (default), the __hash__ method is generated according how cmp and frozen are set.

    1. If both are True, attrs will generate a __hash__ for you.
    2. If cmp is True and frozen is False, __hash__ will be set to None, marking it unhashable (which it is).
    3. If cmp is False, __hash__ will be left untouched meaning the __hash__ method of the base class will be used (if base class is object, this means it will fall back to id-based hashing.).

    Although not recommended, you can decide for yourself and force attrs to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passing True or not. Both of these cases are rather special and should be used carefully.

    See the Python documentation and the GitHub issue that led to the default behavior for more details.

  • init (bool) – Create a __init__ method that initializes the attrs attributes. Leading underscores are stripped for the argument name. If a __attrs_post_init__ method exists on the class, it will be called after the class is fully initialized.
  • slots (bool) – Create a slots-style class that’s more memory-efficient. See slots for further ramifications.
  • frozen (bool) –

    Make instances immutable after initialization. If someone attempts to modify a frozen instance, attr.exceptions.FrozenInstanceError is raised.

    Please note:

    1. This is achieved by installing a custom __setattr__ method on your class so you can’t implement an own one.
    2. True immutability is impossible in Python.
    3. This does have a minor a runtime performance impact when initializing new instances. In other words: __init__ is slightly slower with frozen=True.
    4. If a class is frozen, you cannot modify self in __attrs_post_init__ or a self-written __init__. You can circumvent that limitation by using object.__setattr__(self, "attribute_name", value).
  • weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless slots is also enabled.
  • auto_attribs (bool) –

    If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.

    In this case, you must annotate every field. If attrs encounters a field that is set to an attr.ib() but lacks a type annotation, an attr.exceptions.UnannotatedAttributeError is raised. Use field_name: typing.Any = attr.ib(...) if you don’t want to set a type.

    If you assign a value to those attributes (e.g. x: int = 42), that value becomes the default value like if it were passed using attr.ib(default=42). Passing an instance of Factory also works as expected.

    Attributes annotated as typing.ClassVar are ignored.

  • kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated __init__ (if init is False, this parameter is ignored).
  • cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.
  • auto_exc (bool) –

    If the class subclasses BaseException (which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:

    • the values for cmp and hash are ignored and the instances compare and hash by the instance’s ids (N.B. attrs will not remove existing implementations of __hash__ or the equality methods. It just won’t add own ones.),
    • all attributes that are either passed into __init__ or have a default value are additionally available as a tuple in the args attribute,
    • the value of str is ignored leaving __str__ to base classes.

New in version 16.0.0: slots

New in version 16.1.0: frozen

New in version 16.3.0: str

New in version 16.3.0: Support for __attrs_post_init__.

Changed in version 17.1.0: hash supports None as value which is also the default now.

New in version 17.3.0: auto_attribs

Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.

Changed in version 18.1.0: If these is ordered, the order is retained.

New in version 18.2.0: weakref_slot

Deprecated since version 18.2.0: __lt__, __le__, __gt__, and __ge__ now raise a DeprecationWarning if the classes compared are subclasses of each other. __eq and __ne__ never tried to compared subclasses to each other.

New in version 18.2.0: kw_only

New in version 18.2.0: cache_hash

New in version 19.1.0: auto_exc

mautrix.client.api.types.media module

class mautrix.client.api.types.media.MXOpenGraph(title: str = None, description: str = None, image: mautrix.client.api.types.media.OpenGraphImage = None, video: mautrix.client.api.types.media.OpenGraphVideo = None, audio: mautrix.client.api.types.media.OpenGraphAudio = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

class mautrix.client.api.types.media.MediaRepoConfig(upload_size: int)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

class mautrix.client.api.types.media.OpenGraphAudio(url: NewType.<locals>.new_type = None, mimetype: str = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

class mautrix.client.api.types.media.OpenGraphImage(url: NewType.<locals>.new_type = None, mimetype: str = None, height: int = None, width: int = None, size: int = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

class mautrix.client.api.types.media.OpenGraphVideo(url: NewType.<locals>.new_type = None, mimetype: str = None, height: int = None, width: int = None, size: int = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

mautrix.client.api.types.media.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=True, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False)

A class decorator that adds dunder-methods according to the specified attributes using attr.ib() or the these argument.

Parameters:
  • these (dict of str to attr.ib()) –

    A dictionary of name to attr.ib() mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add __repr__ methods to Django models) or don’t want to.

    If these is not None, attrs will not search the class body for attributes and will not remove any attributes from it.

    If these is an ordered dict (dict on Python 3.6+, collections.OrderedDict otherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.

  • repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful repr output.
  • repr (bool) – Create a __repr__ method with a human readable representation of attrs attributes..
  • str (bool) – Create a __str__ method that is identical to __repr__. This is usually not necessary except for Exceptions.
  • cmp (bool) – Create __eq__, __ne__, __lt__, __le__, __gt__, and __ge__ methods that compare the class as if it were a tuple of its attrs attributes. But the attributes are only compared, if the types of both classes are identical!
  • hash (bool or None) –

    If None (default), the __hash__ method is generated according how cmp and frozen are set.

    1. If both are True, attrs will generate a __hash__ for you.
    2. If cmp is True and frozen is False, __hash__ will be set to None, marking it unhashable (which it is).
    3. If cmp is False, __hash__ will be left untouched meaning the __hash__ method of the base class will be used (if base class is object, this means it will fall back to id-based hashing.).

    Although not recommended, you can decide for yourself and force attrs to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passing True or not. Both of these cases are rather special and should be used carefully.

    See the Python documentation and the GitHub issue that led to the default behavior for more details.

  • init (bool) – Create a __init__ method that initializes the attrs attributes. Leading underscores are stripped for the argument name. If a __attrs_post_init__ method exists on the class, it will be called after the class is fully initialized.
  • slots (bool) – Create a slots-style class that’s more memory-efficient. See slots for further ramifications.
  • frozen (bool) –

    Make instances immutable after initialization. If someone attempts to modify a frozen instance, attr.exceptions.FrozenInstanceError is raised.

    Please note:

    1. This is achieved by installing a custom __setattr__ method on your class so you can’t implement an own one.
    2. True immutability is impossible in Python.
    3. This does have a minor a runtime performance impact when initializing new instances. In other words: __init__ is slightly slower with frozen=True.
    4. If a class is frozen, you cannot modify self in __attrs_post_init__ or a self-written __init__. You can circumvent that limitation by using object.__setattr__(self, "attribute_name", value).
  • weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless slots is also enabled.
  • auto_attribs (bool) –

    If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.

    In this case, you must annotate every field. If attrs encounters a field that is set to an attr.ib() but lacks a type annotation, an attr.exceptions.UnannotatedAttributeError is raised. Use field_name: typing.Any = attr.ib(...) if you don’t want to set a type.

    If you assign a value to those attributes (e.g. x: int = 42), that value becomes the default value like if it were passed using attr.ib(default=42). Passing an instance of Factory also works as expected.

    Attributes annotated as typing.ClassVar are ignored.

  • kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated __init__ (if init is False, this parameter is ignored).
  • cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.
  • auto_exc (bool) –

    If the class subclasses BaseException (which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:

    • the values for cmp and hash are ignored and the instances compare and hash by the instance’s ids (N.B. attrs will not remove existing implementations of __hash__ or the equality methods. It just won’t add own ones.),
    • all attributes that are either passed into __init__ or have a default value are additionally available as a tuple in the args attribute,
    • the value of str is ignored leaving __str__ to base classes.

New in version 16.0.0: slots

New in version 16.1.0: frozen

New in version 16.3.0: str

New in version 16.3.0: Support for __attrs_post_init__.

Changed in version 17.1.0: hash supports None as value which is also the default now.

New in version 17.3.0: auto_attribs

Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.

Changed in version 18.1.0: If these is ordered, the order is retained.

New in version 18.2.0: weakref_slot

Deprecated since version 18.2.0: __lt__, __le__, __gt__, and __ge__ now raise a DeprecationWarning if the classes compared are subclasses of each other. __eq and __ne__ never tried to compared subclasses to each other.

New in version 18.2.0: kw_only

New in version 18.2.0: cache_hash

New in version 19.1.0: auto_exc

mautrix.client.api.types.misc module

class mautrix.client.api.types.misc.PaginatedMessages(start, end, events)

Bases: tuple

end

Alias for field number 1

events

Alias for field number 2

start

Alias for field number 0

class mautrix.client.api.types.misc.PaginationDirection[source]

Bases: enum.Enum

An enumeration.

BACKWARD = 'b'
FORWARD = 'f'
class mautrix.client.api.types.misc.PublicRoomInfo(room_id: NewType.<locals>.new_type, num_joined_members: int, world_readable: bool, guests_can_join: bool, name: str = None, topic: str = None, avatar_url: NewType.<locals>.new_type = None, aliases: List[NewType.<locals>.new_type] = None, canonical_alias: NewType.<locals>.new_type = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

aliases = None
avatar_url = None
canonical_alias = None
name = None
topic = None
class mautrix.client.api.types.misc.RoomAliasInfo(room_id: NewType.<locals>.new_type = None, servers: List[str] = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

room_id = None
servers = None
class mautrix.client.api.types.misc.RoomCreatePreset[source]

Bases: enum.Enum

An enumeration.

PRIVATE = 'private_chat'
PUBLIC = 'public_chat'
TRUSTED_PRIVATE = 'trusted_private_chat'
class mautrix.client.api.types.misc.RoomDirectoryResponse(chunk: List[mautrix.client.api.types.misc.PublicRoomInfo], next_batch: NewType.<locals>.new_type = None, prev_batch: NewType.<locals>.new_type = None, total_room_count_estimate: int = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

next_batch = None
prev_batch = None
total_room_count_estimate = None
class mautrix.client.api.types.misc.RoomDirectoryVisibility[source]

Bases: enum.Enum

An enumeration.

PRIVATE = 'private'
PUBLIC = 'public'
mautrix.client.api.types.misc.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=True, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False)

A class decorator that adds dunder-methods according to the specified attributes using attr.ib() or the these argument.

Parameters:
  • these (dict of str to attr.ib()) –

    A dictionary of name to attr.ib() mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add __repr__ methods to Django models) or don’t want to.

    If these is not None, attrs will not search the class body for attributes and will not remove any attributes from it.

    If these is an ordered dict (dict on Python 3.6+, collections.OrderedDict otherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.

  • repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful repr output.
  • repr (bool) – Create a __repr__ method with a human readable representation of attrs attributes..
  • str (bool) – Create a __str__ method that is identical to __repr__. This is usually not necessary except for Exceptions.
  • cmp (bool) – Create __eq__, __ne__, __lt__, __le__, __gt__, and __ge__ methods that compare the class as if it were a tuple of its attrs attributes. But the attributes are only compared, if the types of both classes are identical!
  • hash (bool or None) –

    If None (default), the __hash__ method is generated according how cmp and frozen are set.

    1. If both are True, attrs will generate a __hash__ for you.
    2. If cmp is True and frozen is False, __hash__ will be set to None, marking it unhashable (which it is).
    3. If cmp is False, __hash__ will be left untouched meaning the __hash__ method of the base class will be used (if base class is object, this means it will fall back to id-based hashing.).

    Although not recommended, you can decide for yourself and force attrs to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passing True or not. Both of these cases are rather special and should be used carefully.

    See the Python documentation and the GitHub issue that led to the default behavior for more details.

  • init (bool) – Create a __init__ method that initializes the attrs attributes. Leading underscores are stripped for the argument name. If a __attrs_post_init__ method exists on the class, it will be called after the class is fully initialized.
  • slots (bool) – Create a slots-style class that’s more memory-efficient. See slots for further ramifications.
  • frozen (bool) –

    Make instances immutable after initialization. If someone attempts to modify a frozen instance, attr.exceptions.FrozenInstanceError is raised.

    Please note:

    1. This is achieved by installing a custom __setattr__ method on your class so you can’t implement an own one.
    2. True immutability is impossible in Python.
    3. This does have a minor a runtime performance impact when initializing new instances. In other words: __init__ is slightly slower with frozen=True.
    4. If a class is frozen, you cannot modify self in __attrs_post_init__ or a self-written __init__. You can circumvent that limitation by using object.__setattr__(self, "attribute_name", value).
  • weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless slots is also enabled.
  • auto_attribs (bool) –

    If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.

    In this case, you must annotate every field. If attrs encounters a field that is set to an attr.ib() but lacks a type annotation, an attr.exceptions.UnannotatedAttributeError is raised. Use field_name: typing.Any = attr.ib(...) if you don’t want to set a type.

    If you assign a value to those attributes (e.g. x: int = 42), that value becomes the default value like if it were passed using attr.ib(default=42). Passing an instance of Factory also works as expected.

    Attributes annotated as typing.ClassVar are ignored.

  • kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated __init__ (if init is False, this parameter is ignored).
  • cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.
  • auto_exc (bool) –

    If the class subclasses BaseException (which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:

    • the values for cmp and hash are ignored and the instances compare and hash by the instance’s ids (N.B. attrs will not remove existing implementations of __hash__ or the equality methods. It just won’t add own ones.),
    • all attributes that are either passed into __init__ or have a default value are additionally available as a tuple in the args attribute,
    • the value of str is ignored leaving __str__ to base classes.

New in version 16.0.0: slots

New in version 16.1.0: frozen

New in version 16.3.0: str

New in version 16.3.0: Support for __attrs_post_init__.

Changed in version 17.1.0: hash supports None as value which is also the default now.

New in version 17.3.0: auto_attribs

Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.

Changed in version 18.1.0: If these is ordered, the order is retained.

New in version 18.2.0: weakref_slot

Deprecated since version 18.2.0: __lt__, __le__, __gt__, and __ge__ now raise a DeprecationWarning if the classes compared are subclasses of each other. __eq and __ne__ never tried to compared subclasses to each other.

New in version 18.2.0: kw_only

New in version 18.2.0: cache_hash

New in version 19.1.0: auto_exc

mautrix.client.api.types.primitive module

mautrix.client.api.types.users module

class mautrix.client.api.types.users.Member(membership: <unknown>.Membership = None, avatar_url: NewType.<locals>.new_type = None, displayname: str = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

avatar_url = None
displayname = None
membership = None
class mautrix.client.api.types.users.User(user_id: NewType.<locals>.new_type, avatar_url: NewType.<locals>.new_type = None, displayname: str = None)[source]

Bases: mautrix.client.api.types.util.serializable_attrs.SerializableAttrs

avatar_url = None
displayname = None
class mautrix.client.api.types.users.UserSearchResults(results, limit)

Bases: tuple

limit

Alias for field number 1

results

Alias for field number 0

mautrix.client.api.types.users.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=True, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False)

A class decorator that adds dunder-methods according to the specified attributes using attr.ib() or the these argument.

Parameters:
  • these (dict of str to attr.ib()) –

    A dictionary of name to attr.ib() mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add __repr__ methods to Django models) or don’t want to.

    If these is not None, attrs will not search the class body for attributes and will not remove any attributes from it.

    If these is an ordered dict (dict on Python 3.6+, collections.OrderedDict otherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.

  • repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful repr output.
  • repr (bool) – Create a __repr__ method with a human readable representation of attrs attributes..
  • str (bool) – Create a __str__ method that is identical to __repr__. This is usually not necessary except for Exceptions.
  • cmp (bool) – Create __eq__, __ne__, __lt__, __le__, __gt__, and __ge__ methods that compare the class as if it were a tuple of its attrs attributes. But the attributes are only compared, if the types of both classes are identical!
  • hash (bool or None) –

    If None (default), the __hash__ method is generated according how cmp and frozen are set.

    1. If both are True, attrs will generate a __hash__ for you.
    2. If cmp is True and frozen is False, __hash__ will be set to None, marking it unhashable (which it is).
    3. If cmp is False, __hash__ will be left untouched meaning the __hash__ method of the base class will be used (if base class is object, this means it will fall back to id-based hashing.).

    Although not recommended, you can decide for yourself and force attrs to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passing True or not. Both of these cases are rather special and should be used carefully.

    See the Python documentation and the GitHub issue that led to the default behavior for more details.

  • init (bool) – Create a __init__ method that initializes the attrs attributes. Leading underscores are stripped for the argument name. If a __attrs_post_init__ method exists on the class, it will be called after the class is fully initialized.
  • slots (bool) – Create a slots-style class that’s more memory-efficient. See slots for further ramifications.
  • frozen (bool) –

    Make instances immutable after initialization. If someone attempts to modify a frozen instance, attr.exceptions.FrozenInstanceError is raised.

    Please note:

    1. This is achieved by installing a custom __setattr__ method on your class so you can’t implement an own one.
    2. True immutability is impossible in Python.
    3. This does have a minor a runtime performance impact when initializing new instances. In other words: __init__ is slightly slower with frozen=True.
    4. If a class is frozen, you cannot modify self in __attrs_post_init__ or a self-written __init__. You can circumvent that limitation by using object.__setattr__(self, "attribute_name", value).
  • weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless slots is also enabled.
  • auto_attribs (bool) –

    If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.

    In this case, you must annotate every field. If attrs encounters a field that is set to an attr.ib() but lacks a type annotation, an attr.exceptions.UnannotatedAttributeError is raised. Use field_name: typing.Any = attr.ib(...) if you don’t want to set a type.

    If you assign a value to those attributes (e.g. x: int = 42), that value becomes the default value like if it were passed using attr.ib(default=42). Passing an instance of Factory also works as expected.

    Attributes annotated as typing.ClassVar are ignored.

  • kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated __init__ (if init is False, this parameter is ignored).
  • cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.
  • auto_exc (bool) –

    If the class subclasses BaseException (which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:

    • the values for cmp and hash are ignored and the instances compare and hash by the instance’s ids (N.B. attrs will not remove existing implementations of __hash__ or the equality methods. It just won’t add own ones.),
    • all attributes that are either passed into __init__ or have a default value are additionally available as a tuple in the args attribute,
    • the value of str is ignored leaving __str__ to base classes.

New in version 16.0.0: slots

New in version 16.1.0: frozen

New in version 16.3.0: str

New in version 16.3.0: Support for __attrs_post_init__.

Changed in version 17.1.0: hash supports None as value which is also the default now.

New in version 17.3.0: auto_attribs

Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.

Changed in version 18.1.0: If these is ordered, the order is retained.

New in version 18.2.0: weakref_slot

Deprecated since version 18.2.0: __lt__, __le__, __gt__, and __ge__ now raise a DeprecationWarning if the classes compared are subclasses of each other. __eq and __ne__ never tried to compared subclasses to each other.

New in version 18.2.0: kw_only

New in version 18.2.0: cache_hash

New in version 19.1.0: auto_exc

Module contents