Skip to content

User

Wrapper for Notion user objects.

Bot

Bases: User

Represents a Bot in Notion.

Source code in src/notional/user.py
55
56
57
58
59
60
61
62
63
64
65
class Bot(User):
    """Represents a Bot in Notion."""

    class _NestedData(GenericObject):
        pass

    bot: _NestedData = None

    def __str__(self):
        """Return a string representation of this `Bot`."""
        return f"[%{self.name}]"

__str__()

Return a string representation of this Bot.

Source code in src/notional/user.py
63
64
65
def __str__(self):
    """Return a string representation of this `Bot`."""
    return f"[%{self.name}]"

Person

Bases: User

Represents a Person in Notion.

Source code in src/notional/user.py
42
43
44
45
46
47
48
49
50
51
52
class Person(User):
    """Represents a Person in Notion."""

    class _NestedData(GenericObject):
        email: str

    person: _NestedData = None

    def __str__(self):
        """Return a string representation of this `Person`."""
        return f"[@{self.name}]"

__str__()

Return a string representation of this Person.

Source code in src/notional/user.py
50
51
52
def __str__(self):
    """Return a string representation of this `Person`."""
    return f"[@{self.name}]"

User

Bases: NotionObject

Represents a User in Notion.

Source code in src/notional/user.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class User(NotionObject, object="user"):
    """Represents a User in Notion."""

    # XXX why isn't this a TypedObject ?

    type: Optional[UserType] = None
    name: Optional[str] = None
    avatar_url: Optional[str] = None

    @classmethod
    def parse_obj(cls, obj):
        """Attempt to parse the given object data into the correct `User` type."""

        if obj is None:
            return None

        if "type" in obj:
            if obj["type"] == "person":
                return Person(**obj)

            if obj["type"] == "bot":
                return Bot(**obj)

        return cls(obj)

parse_obj(obj) classmethod

Attempt to parse the given object data into the correct User type.

Source code in src/notional/user.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@classmethod
def parse_obj(cls, obj):
    """Attempt to parse the given object data into the correct `User` type."""

    if obj is None:
        return None

    if "type" in obj:
        if obj["type"] == "person":
            return Person(**obj)

        if obj["type"] == "bot":
            return Bot(**obj)

    return cls(obj)

UserType

Bases: str, Enum

Available user types.

Source code in src/notional/user.py
 9
10
11
12
13
class UserType(str, Enum):
    """Available user types."""

    PERSON = "person"
    BOT = "bot"