Feed

lobstr.models.feed.Feed

Bases: PageMixin

A Feed is an array of posts along with pagination info

Attributes:

Name Type Description
posts list[Post]

A list of Post objects in the feed

page int

The current page number

Source code in lobstr/models/feed.py
 6
 7
 8
 9
10
11
12
13
14
15
class Feed(PageMixin):
    """
    A Feed is an array of posts along with pagination info

    Attributes:
        posts (list[Post]): A list of Post objects in the feed
        page (int): The current page number
    """

    posts: list[Post] = Field(default_factory=list)

Post

lobstr.models.post.Post

Bases: BaseModel

Represents a post on the lobste.rs home page.

Attributes:

Name Type Description
id str

The unique identifier for the post.

description Content

The description of the post, including both HTML (.description) and plain text versions (.description.plain).

created_at datetime

The timestamp when the post was created.

title str

The title of the post.

score int

The score of the post, representing upvotes minus downvotes.

flags int

The number of flags the post has received.

tags list[str]

A list of tags associated with the post.

comment_count int

The number of comments on the post.

username str

The username of the poster.

article_url str

The URL of the article linked to the post.

url URLPair

A pair of URLs for the post, including canonical (.url.canonical) and short (.url.short) versions.

Source code in lobstr/models/post.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Post(BaseModel):
    """
    Represents a post on the lobste.rs [home page](https://lobste.rs).

    Attributes:
        id (str): The unique identifier for the post.
        description (Content): The description of the post, including both HTML (`.description`) and plain text versions (`.description.plain`).
        created_at (datetime): The timestamp when the post was created.
        title (str): The title of the post.
        score (int): The score of the post, representing upvotes minus downvotes.
        flags (int): The number of flags the post has received.
        tags (list[str]): A list of [tags](https://lobste.rs/tags) associated with the post.
        comment_count (int): The number of comments on the post.
        username (str): The username of the poster.
        article_url (str): The URL of the article linked to the post.
        url (URLPair): A pair of URLs for the post, including canonical (`.url.canonical`) and short (`.url.short`) versions.
    """

    model_config = ConfigDict(
        arbitrary_types_allowed=True,
        extra="ignore",
    )

    id: str = Field(validation_alias="short_id")
    description: Content

    created_at: datetime

    title: str
    score: int
    flags: int
    comment_count: int
    username: str = Field(validation_alias="submitter_user")

    article_url: str
    url: URLPair

    tags: list[str] = Field(default_factory=list)

    @model_validator(mode="before")
    @classmethod
    def post_preprocessing(cls, data):
        if isinstance(data, dict):
            data["description"] = Content(
                data.pop("description", ""),
                data.pop("description_plain", ""),
            )
            data["article_url"] = data.pop("url")

            data["url"] = URLPair(
                canonical=data.pop("comments_url"),
                short=data.pop("short_id_url"),
            )

        return data

Story

lobstr.models.story.Story

Bases: Post

Represents a Story i.e. A Post & Its comments

Attributes:

Name Type Description
id str

The unique identifier for the post.

description Content

The description of the post, including both HTML (.description) and plain text versions (.description.plain).

created_at datetime

The timestamp when the post was created.

title str

The title of the post.

score int

The score of the post, representing upvotes minus downvotes.

flags int

The number of flags the post has received.

tags list[str]

A list of tags associated with the post.

comment_count int

The number of comments on the post.

username str

The username of the poster.

article_url str

The URL of the article linked to the post.

url URLPair

A pair of URLs for the post, including canonical (.url.canonical) and short (.url.short) versions.

comments List[Comment]

A list of comments associated with the story

Source code in lobstr/models/story.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Story(Post):
    """
    Represents a [Story](https://lobste.rs/s/109l2t) i.e. A Post & Its comments

    Attributes:
        id (str): The unique identifier for the post.
        description (Content): The description of the post, including both HTML (`.description`) and plain text versions (`.description.plain`).
        created_at (datetime): The timestamp when the post was created.
        title (str): The title of the post.
        score (int): The score of the post, representing upvotes minus downvotes.
        flags (int): The number of flags the post has received.
        tags (list[str]): A list of [tags](https://lobste.rs/tags) associated with the post.
        comment_count (int): The number of comments on the post.
        username (str): The username of the poster.
        article_url (str): The URL of the article linked to the post.
        url (URLPair): A pair of URLs for the post, including canonical (`.url.canonical`) and short (`.url.short`) versions.
        comments (List[Comment]): A list of comments associated with the story
    """

    comments: List[Comment] = Field(default_factory=list)

Comment

lobstr.models.comment.Comment

Bases: BaseModel

Represents a comment on a post.

Attributes:

Name Type Description
id str

The unique identifier for the comment.

created_at datetime

The timestamp when the comment was created.

edited_at Optional[datetime]

The timestamp when the comment was last edited, if applicable.

is_deleted bool

Indicates whether the comment has been deleted.

is_moderated bool

Indicates whether the comment has been moderated.

score int

The score of the comment, representing upvotes minus downvotes.

flags int

The number of flags the comment has received.

depth int

The depth of the comment in the thread hierarchy.

username str

The username of the commenter.

content Content

The content of the comment, including both HTML (.content) and plain text versions (.content.plain).

parent Optional[str]

The ID of the parent comment, if this comment is a reply.

url URLPair

URLs linking to the comment, url.canonical and url.short versions.

Source code in lobstr/models/comment.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Comment(BaseModel):
    """
    Represents a comment on a [post](https://lobste.rs/c/szmc6l).

    Attributes:
        id (str): The unique identifier for the comment.
        created_at (datetime): The timestamp when the comment was created.
        edited_at (Optional[datetime]): The timestamp when the comment was last edited, if applicable.
        is_deleted (bool): Indicates whether the comment has been deleted.
        is_moderated (bool): Indicates whether the comment has been moderated.
        score (int): The score of the comment, representing upvotes minus downvotes.
        flags (int): The number of flags the comment has received.
        depth (int): The depth of the comment in the thread hierarchy.
        username (str): The username of the commenter.
        content (Content): The content of the comment, including both HTML (`.content`) and plain text versions (`.content.plain`).
        parent (Optional[str]): The ID of the parent comment, if this comment is a reply.
        url (URLPair): URLs linking to the comment, `url.canonical` and `url.short` versions.
    """

    model_config = ConfigDict(
        arbitrary_types_allowed=True,
        extra="ignore",
    )

    id: str = Field(validation_alias="short_id")

    created_at: datetime
    edited_at: Optional[datetime] = Field(
        default=None,
        validation_alias="last_edited_at",
    )

    is_deleted: bool
    is_moderated: bool

    score: int
    flags: int
    depth: int

    username: str = Field(validation_alias="commenting_user")

    content: Content

    parent: Optional[str] = Field(
        default=None,
        validation_alias="parent_comment",
    )

    url: URLPair

    @model_validator(mode="before")
    @classmethod
    def comment_preprocessing(cls, data: Any):
        if isinstance(data, dict):
            data["content"] = Content(
                data.pop("comment", ""),
                data.pop("comment_plain", ""),
            )

            data["url"] = URLPair(
                canonical=data.pop("url"),
                short=data.pop("short_id_url"),
            )

        return data

User

lobstr.models.user.User

Bases: BaseModel

represents a user.

Attributes:

Name Type Description
username str

The user's username.

karma int

The user's karma score.

about str

The user's about section.

avatar_url str

The URL of the user's avatar image.

created_at datetime

The date and time when the user was created.

is_admin bool

Whether the user is an admin.

is_moderator bool

Whether the user is a moderator.

invited_by_user Optional[str]

The username of the user who invited this user, if applicable.

Source code in lobstr/models/user.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class User(BaseModel):
    """
    represents a [user](https://lobste.rs/~pushcx).

    Attributes:
        username (str): The user's username.
        karma (int): The user's karma score.
        about (str): The user's about section.
        avatar_url (str): The URL of the user's avatar image.
        created_at (datetime): The date and time when the user was created.
        is_admin (bool): Whether the user is an admin.
        is_moderator (bool): Whether the user is a moderator.
        invited_by_user (Optional[str]): The username of the user who invited this user, if applicable.
    """

    username: str
    karma: int
    about: str
    avatar_url: str

    created_at: datetime

    is_admin: bool
    is_moderator: bool

    invited_by_user: Optional[str] = None

Tag

lobstr.models.tag.Tag

Bases: BaseModel

Represents metadata related to a tag.

Attributes:

Name Type Description
name str

The name of the tag.

description str

A brief description of the tag.

category str

The category of the tag.

is_privileged bool

Indicates if the tag needs additional permissions to be used.

is_media bool

Indicates if the tag is related to media content.

is_active bool

Indicates if the tag is currently active.

hotness_mod float

A modifier that affects the "hotness" score of stories (used for home page ranking)

Source code in lobstr/models/tag.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Tag(BaseModel):
    """
    Represents metadata related to a [tag](https://lobste.rs/tags).

    Attributes:
        name (str): The name of the tag.
        description (str): A brief description of the tag.
        category (str): The category of the tag.
        is_privileged (bool): Indicates if the tag needs additional permissions to be used.
        is_media (bool): Indicates if the tag is related to media content.
        is_active (bool): Indicates if the tag is currently active.
        hotness_mod (float): A modifier that affects the "hotness" score of stories (used for home page ranking)
    """

    name: str = Field(..., alias="tag")
    description: str
    category: str

    is_privileged: bool = Field(..., alias="privileged")
    is_media: bool
    is_active: bool = Field(..., alias="active")

    hotness_mod: float

Content

lobstr.models.core.Content

Bases: str

A string subclass that holds both the original content and a plain version of it.

Attributes:

Name Type Description
cls/self str

The original HTML content.

plain str

The plain version of the content.

Source code in lobstr/models/core.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Content(str):
    """
    A string subclass that holds both the original content and a plain version of it.

    Attributes:
        cls/self (str): The original HTML content.
        plain (str): The plain version of the content.
    """

    __slots__ = ("plain",)

    def __new__(cls, content: str, plain_content: str):
        obj = super().__new__(cls, content)
        obj.plain = plain_content
        return obj

URLPair

lobstr.models.core.URLPair dataclass

dataclass that holds both canonical and short versions of a URL to a resource.

Attributes:

Name Type Description
canonical str

The canonical version of the URL.

short str

The shortened version of the URL.

Source code in lobstr/models/core.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@dataclass(frozen=True)
class URLPair:
    """
    dataclass that holds both canonical and short versions of a URL to a resource.

    Attributes:
        canonical (str): The canonical version of the URL.
        short (str): The shortened version of the URL.
    """

    canonical: str
    short: str