Skip to content

Endpoints


Endpoints for Ravelry

pyravelry.endpoints.ColorFamiliesResource

Bases: BaseEndpoint

Endpoint for Color Families.

Attributes:

Name Type Description
BaseEndpoint AnyUrl

The endpoint for colorfamily.

output_model ColorFamiliesModel

The pydantic model that the api output is validated against.

Methods:

Name Description
list

returns all color families.

Color Family Ravelry API documentation

Source code in src/pyravelry/endpoints/color_families.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class ColorFamiliesResource(BaseEndpoint):
    """Endpoint for Color Families.

    Attributes:
        BaseEndpoint (AnyUrl): The endpoint for colorfamily.
        output_model (ColorFamiliesModel): The pydantic model that the api output is validated against.

    Methods:
        list (list[ColorFamilyModel]): returns all color families.

    [Color Family Ravelry API documentation](https://www.ravelry.com/api#/_color_families)
    """

    actions = TypedNamespace(
        list=Action("/color_families.json", ColorFamiliesModel),
    )

    def list(self) -> ColorFamiliesModel:
        """
        Retrieves all color families from Ravelry.
        """
        response_dict = self._fetch(self._http.get(self.actions.list.url))
        return cast(ColorFamiliesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.ColorFamiliesResource.list()

Retrieves all color families from Ravelry.

Source code in src/pyravelry/endpoints/color_families.py
24
25
26
27
28
29
def list(self) -> ColorFamiliesModel:
    """
    Retrieves all color families from Ravelry.
    """
    response_dict = self._fetch(self._http.get(self.actions.list.url))
    return cast(ColorFamiliesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.CommentsResource

Bases: BaseEndpoint

Endpoint for Comments.

Methods:

Name Description
create

Post a comment related to an object.

delete

Delete a specific comment by ID.

list

Get list of comments left by a user.

Comments Ravelry API documentation

Source code in src/pyravelry/endpoints/comments.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class CommentsResource(BaseEndpoint):
    """Endpoint for Comments.

    Methods:
        create (CommentFullModel): Post a comment related to an object.
        delete (CommentFullModel): Delete a specific comment by ID.
        list (list[CommentHistoryModel]): Get list of comments left by a user.

    [Comments Ravelry API documentation](https://www.ravelry.com/api#/_comments)
    """

    actions = TypedNamespace(
        create=Action("/comments/create.json", CommentFullModel),
        delete=Action("/comments/{}.json", CommentFullModel),
        list=Action("/people/{}/comments/list.json", CommentHistoriesModel),
    )

    @validate_call
    def create(
        self, type_: Literal["project", "pattern", "yarn", "stash"], commented_id: int, body: str, reply_to_id: int
    ) -> CommentFullModel:
        """
        Post a comment related to an object (project, pattern, yarn, or stash).

        Arguments:
            type_ (Literal["project", "pattern", "yarn", "stash"]): The type of item being commented on.
            commented_id (int): ID of the item being commented on.
            body (str): Comment body.
            reply_to_id (int): ID of the comment being replied to. Restricted to item owners.

        Returns:
            (CommentFullModel): The published comment
        """

        payload = {
            "type": type_,
            "commented_id": commented_id,
            "body": body,
            "reply_to_id": reply_to_id,
        }

        response_dict = self._fetch(self._http.post(self.actions.create.url, params=payload))

        return cast(CommentFullModel, self.actions.create.model.model_validate(response_dict["comment"]))

    @validate_call
    def delete(self, id_: int) -> CommentFullModel:
        """
        Delete a comment by its ID.

        Arguments:
            id_ (int): The comment ID to delete.

        Returns:
            (CommentFullModel): The deleted comment.
        """
        response_dict = self._fetch(self._http.delete(self.actions.delete.url.format(id_)))

        return cast(CommentFullModel, self.actions.delete.model.model_validate(response_dict["comment"]))

    @validate_call
    def list(self, username: str, page: int = 1, page_size: int = 25) -> CommentHistoriesModel:
        """
        Get list of comments left by a specific user.

        Args:
            username (str): username to be retrieved
            page (int, optional): page number. Defaults to 1.
            page_size (int, optional): size of page. Defaults to 25.

        Returns:
            CommentHistoriesModel: The comment history for a particular username.
        """
        params = SimplifiedPaginator(page=page, page_size=page_size)

        response_dict = self._fetch(
            self._http.get(self.actions.list.url.format(str(username)), params=params.model_dump())
        )

        return cast(CommentHistoriesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.CommentsResource.create(type_, commented_id, body, reply_to_id)

Post a comment related to an object (project, pattern, yarn, or stash).

Parameters:

Name Type Description Default
type_ Literal['project', 'pattern', 'yarn', 'stash']

The type of item being commented on.

required
commented_id int

ID of the item being commented on.

required
body str

Comment body.

required
reply_to_id int

ID of the comment being replied to. Restricted to item owners.

required

Returns:

Type Description
CommentFullModel

The published comment

Source code in src/pyravelry/endpoints/comments.py
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
@validate_call
def create(
    self, type_: Literal["project", "pattern", "yarn", "stash"], commented_id: int, body: str, reply_to_id: int
) -> CommentFullModel:
    """
    Post a comment related to an object (project, pattern, yarn, or stash).

    Arguments:
        type_ (Literal["project", "pattern", "yarn", "stash"]): The type of item being commented on.
        commented_id (int): ID of the item being commented on.
        body (str): Comment body.
        reply_to_id (int): ID of the comment being replied to. Restricted to item owners.

    Returns:
        (CommentFullModel): The published comment
    """

    payload = {
        "type": type_,
        "commented_id": commented_id,
        "body": body,
        "reply_to_id": reply_to_id,
    }

    response_dict = self._fetch(self._http.post(self.actions.create.url, params=payload))

    return cast(CommentFullModel, self.actions.create.model.model_validate(response_dict["comment"]))

pyravelry.endpoints.CommentsResource.delete(id_)

Delete a comment by its ID.

Parameters:

Name Type Description Default
id_ int

The comment ID to delete.

required

Returns:

Type Description
CommentFullModel

The deleted comment.

Source code in src/pyravelry/endpoints/comments.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@validate_call
def delete(self, id_: int) -> CommentFullModel:
    """
    Delete a comment by its ID.

    Arguments:
        id_ (int): The comment ID to delete.

    Returns:
        (CommentFullModel): The deleted comment.
    """
    response_dict = self._fetch(self._http.delete(self.actions.delete.url.format(id_)))

    return cast(CommentFullModel, self.actions.delete.model.model_validate(response_dict["comment"]))

pyravelry.endpoints.CommentsResource.list(username, page=1, page_size=25)

Get list of comments left by a specific user.

Parameters:

Name Type Description Default
username str

username to be retrieved

required
page int

page number. Defaults to 1.

1
page_size int

size of page. Defaults to 25.

25

Returns:

Name Type Description
CommentHistoriesModel CommentHistoriesModel

The comment history for a particular username.

Source code in src/pyravelry/endpoints/comments.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@validate_call
def list(self, username: str, page: int = 1, page_size: int = 25) -> CommentHistoriesModel:
    """
    Get list of comments left by a specific user.

    Args:
        username (str): username to be retrieved
        page (int, optional): page number. Defaults to 1.
        page_size (int, optional): size of page. Defaults to 25.

    Returns:
        CommentHistoriesModel: The comment history for a particular username.
    """
    params = SimplifiedPaginator(page=page, page_size=page_size)

    response_dict = self._fetch(
        self._http.get(self.actions.list.url.format(str(username)), params=params.model_dump())
    )

    return cast(CommentHistoriesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.CurrentUserResource

Bases: BaseEndpoint

Endpoint for the currently authenticated user.

Attributes:

Name Type Description
endpoint str

The endpoint for current_user.

output_model UserModel

The pydantic model that the api output is validated against.

Methods:

Name Description
get

Returns the authenticated user's details.

Current User Ravelry API documentation

Source code in src/pyravelry/endpoints/current_user.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class CurrentUserResource(BaseEndpoint):
    """Endpoint for the currently authenticated user.

    Attributes:
        endpoint (str): The endpoint for current_user.
        output_model (UserModel): The pydantic model that the api output is validated against.

    Methods:
        get (UserModel): Returns the authenticated user's details.

    [Current User Ravelry API documentation](https://www.ravelry.com/api#/_current_user)
    """

    actions = TypedNamespace(get=Action("/current_user.json", UserModel))

    def get(self) -> UserModel:
        """
        Retrieves the details of the currently authenticated user.
        """
        response_dict = self._fetch(self._http.get(self.actions.get.url))
        return cast(UserModel, self.actions.get.model.model_validate(response_dict))

pyravelry.endpoints.CurrentUserResource.get()

Retrieves the details of the currently authenticated user.

Source code in src/pyravelry/endpoints/current_user.py
22
23
24
25
26
27
def get(self) -> UserModel:
    """
    Retrieves the details of the currently authenticated user.
    """
    response_dict = self._fetch(self._http.get(self.actions.get.url))
    return cast(UserModel, self.actions.get.model.model_validate(response_dict))

pyravelry.endpoints.FiberAttributesResource

Bases: BaseEndpoint

Endpoint for Fiber Attributes.

Attributes:

Name Type Description
BaseEndpoint AnyUrl

The endpoint for fiber attributes.

Methods:

Name Description
list

returns all fiber attributes.

Fiber Attributes Ravelry API documentation

Source code in src/pyravelry/endpoints/fiber_attributes.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class FiberAttributesResource(BaseEndpoint):
    """Endpoint for Fiber Attributes.

    Attributes:
        BaseEndpoint (AnyUrl): The endpoint for fiber attributes.

    Methods:
        list (list[FiberAttributeModel]): returns all fiber attributes.

    [Fiber Attributes Ravelry API documentation](https://www.ravelry.com/api#/_fiber_attributes)
    """

    actions = TypedNamespace(list=Action("/fiber_attributes.json", FiberAttributesModel))

    def list(self) -> FiberAttributesModel:
        """
        List the current fiber attributes

        Endpoint: GET /fiber_attributes.json
        """
        response_dict = self._fetch(self._http.get(self.actions.list.url))
        return cast(FiberAttributesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.FiberAttributesResource.list()

List the current fiber attributes

Endpoint: GET /fiber_attributes.json

Source code in src/pyravelry/endpoints/fiber_attributes.py
21
22
23
24
25
26
27
28
def list(self) -> FiberAttributesModel:
    """
    List the current fiber attributes

    Endpoint: GET /fiber_attributes.json
    """
    response_dict = self._fetch(self._http.get(self.actions.list.url))
    return cast(FiberAttributesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.FiberCategoriesResource

Bases: BaseEndpoint

Endpoint for Fiber Categories.

Attributes:

Name Type Description
BaseEndpoint AnyUrl

The endpoint for fiber categories.

Methods:

Name Description
list

returns all fiber categories.

Fiber Categories Ravelry API documentation

Source code in src/pyravelry/endpoints/fiber_categories.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class FiberCategoriesResource(BaseEndpoint):
    """Endpoint for Fiber Categories.

    Attributes:
        BaseEndpoint (AnyUrl): The endpoint for fiber categories.

    Methods:
        list (list[FiberCategoryModel]): returns all fiber categories.

    [Fiber Categories Ravelry API documentation](https://www.ravelry.com/api#/_fiber_categories)
    """

    actions = TypedNamespace(list=Action("/fiber_categories.json", FiberCategoriesModel))

    def list(self) -> FiberCategoriesModel:
        """
        List the current fiber categories
        Endpoint: GET /fiber_categories.json
        """
        response_dict = self._fetch(self._http.get(self.actions.list.url))
        return cast(FiberCategoriesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.FiberCategoriesResource.list()

List the current fiber categories Endpoint: GET /fiber_categories.json

Source code in src/pyravelry/endpoints/fiber_categories.py
21
22
23
24
25
26
27
def list(self) -> FiberCategoriesModel:
    """
    List the current fiber categories
    Endpoint: GET /fiber_categories.json
    """
    response_dict = self._fetch(self._http.get(self.actions.list.url))
    return cast(FiberCategoriesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.NeedlesResource

Bases: BaseEndpoint

Needles endpoint for Ravelry.

Handles user needle inventories, global needle sizes, and needle types.

Source code in src/pyravelry/endpoints/needles.py
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
class NeedlesResource(BaseEndpoint):
    """Needles endpoint for Ravelry.

    Handles user needle inventories, global needle sizes, and needle types.
    """

    actions = TypedNamespace(
        list=Action("/people/{}/needles/list.json", NeedleRecordListModel),
        sizes=Action("/needles/sizes.json", NeedleSizesModel),
        types=Action("/needles/types.json", NeedleTypesModel),
    )

    @validate_call
    def list(self, username: str) -> NeedleRecordListModel:
        """
        Get needle records for a specific user.

        Args:
            username (str): Username or integer ID of the user to retrieve needles for.

        Returns:
            NeedleRecordsListModel: The user's list of needle records.
        """
        response_dict = self._fetch(self._http.get(self.actions.list.url.format(username)))

        return cast(NeedleRecordListModel, self.actions.list.model.model_validate(response_dict))

    @validate_call
    def sizes(self, craft: Optional[Literal["crochet", "knitting"]] = None) -> NeedleSizesModel:
        """
        Get available sizes for each needle type.

        Args:
            craft (str | None): Filter by tool type. "crochet" for hooks only,
                                "knitting" for knitting needles only. Defaults to None.

        Returns:
            NeedleSizesListModel: The list of available needle sizes.
        """
        params = {"craft": craft} if craft else {}

        response_dict = self._fetch(self._http.get(self.actions.sizes.url, params=params))

        return cast(NeedleSizesModel, self.actions.sizes.model.model_validate(response_dict))

    @validate_call
    def types(self) -> NeedleTypesModel:
        """
        Get all global needle types.

        Returns:
            NeedleTypesModel: The list of available needle types.
        """
        response_dict = self._fetch(self._http.get(self.actions.types.url))

        return cast(NeedleTypesModel, self.actions.types.model.model_validate(response_dict))

pyravelry.endpoints.NeedlesResource.list(username)

Get needle records for a specific user.

Parameters:

Name Type Description Default
username str

Username or integer ID of the user to retrieve needles for.

required

Returns:

Name Type Description
NeedleRecordsListModel NeedleRecordListModel

The user's list of needle records.

Source code in src/pyravelry/endpoints/needles.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@validate_call
def list(self, username: str) -> NeedleRecordListModel:
    """
    Get needle records for a specific user.

    Args:
        username (str): Username or integer ID of the user to retrieve needles for.

    Returns:
        NeedleRecordsListModel: The user's list of needle records.
    """
    response_dict = self._fetch(self._http.get(self.actions.list.url.format(username)))

    return cast(NeedleRecordListModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.NeedlesResource.sizes(craft=None)

Get available sizes for each needle type.

Parameters:

Name Type Description Default
craft str | None

Filter by tool type. "crochet" for hooks only, "knitting" for knitting needles only. Defaults to None.

None

Returns:

Name Type Description
NeedleSizesListModel NeedleSizesModel

The list of available needle sizes.

Source code in src/pyravelry/endpoints/needles.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@validate_call
def sizes(self, craft: Optional[Literal["crochet", "knitting"]] = None) -> NeedleSizesModel:
    """
    Get available sizes for each needle type.

    Args:
        craft (str | None): Filter by tool type. "crochet" for hooks only,
                            "knitting" for knitting needles only. Defaults to None.

    Returns:
        NeedleSizesListModel: The list of available needle sizes.
    """
    params = {"craft": craft} if craft else {}

    response_dict = self._fetch(self._http.get(self.actions.sizes.url, params=params))

    return cast(NeedleSizesModel, self.actions.sizes.model.model_validate(response_dict))

pyravelry.endpoints.NeedlesResource.types()

Get all global needle types.

Returns:

Name Type Description
NeedleTypesModel NeedleTypesModel

The list of available needle types.

Source code in src/pyravelry/endpoints/needles.py
58
59
60
61
62
63
64
65
66
67
68
@validate_call
def types(self) -> NeedleTypesModel:
    """
    Get all global needle types.

    Returns:
        NeedleTypesModel: The list of available needle types.
    """
    response_dict = self._fetch(self._http.get(self.actions.types.url))

    return cast(NeedleTypesModel, self.actions.types.model.model_validate(response_dict))

pyravelry.endpoints.PeopleResource

Bases: BaseEndpoint

People endpoint for Ravelry.

People Ravelry API documentation

Source code in src/pyravelry/endpoints/people.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
class PeopleResource(BaseEndpoint):
    """People endpoint for Ravelry.

    [People Ravelry API documentation](https://www.ravelry.com/api#people_show)
    """

    actions = TypedNamespace(
        show=Action("/people/{}.json", UserModel),
        update=Action("/people/{}.json", UserModel),
    )

    @validate_call
    def show(self, username: str) -> UserModel:
        """
        Get a user's profile information.

        Args:
            username (str): Username or integer ID of the user to lookup.

        Returns:
            UserFullModel: The full user profile data.
        """
        response_dict = self._fetch(self._http.get(self.actions.show.url.format(username)))

        return cast(UserModel, self.actions.show.model.model_validate(response_dict))

    @validate_call
    def update(
        self,
        username: str,
        first_name: str | None = None,
        about_me: str | None = None,
        fave_colors: str | None = None,
        fave_curse: str | None = None,
        location: str | None = None,
    ) -> UserModel:
        """
        Update a user's profile. Requires profile-write permission.

        Args:
            username (str): Username or integer ID of the user to update.
            first_name (str | None): User's first name.
            about_me (str | None): User's "About Me" description.
            fave_colors (str | None): User's favorite colors.
            fave_curse (str | None): User's favorite curse word.
            location (str | None): User's location.

        Returns:
            UserFullModel: The updated user profile.
        """
        update_data = {
            "first_name": first_name,
            "about_me": about_me,
            "fave_colors": fave_colors,
            "fave_curse": fave_curse,
            "location": location,
        }

        payload = UserPostModel(**update_data).model_dump(exclude_unset=True)

        response_dict = self._fetch(self._http.post(self.actions.update.url.format(username), json=payload))

        return cast(UserModel, self.actions.update.model.model_validate(response_dict))

pyravelry.endpoints.PeopleResource.show(username)

Get a user's profile information.

Parameters:

Name Type Description Default
username str

Username or integer ID of the user to lookup.

required

Returns:

Name Type Description
UserFullModel UserModel

The full user profile data.

Source code in src/pyravelry/endpoints/people.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@validate_call
def show(self, username: str) -> UserModel:
    """
    Get a user's profile information.

    Args:
        username (str): Username or integer ID of the user to lookup.

    Returns:
        UserFullModel: The full user profile data.
    """
    response_dict = self._fetch(self._http.get(self.actions.show.url.format(username)))

    return cast(UserModel, self.actions.show.model.model_validate(response_dict))

pyravelry.endpoints.PeopleResource.update(username, first_name=None, about_me=None, fave_colors=None, fave_curse=None, location=None)

Update a user's profile. Requires profile-write permission.

Parameters:

Name Type Description Default
username str

Username or integer ID of the user to update.

required
first_name str | None

User's first name.

None
about_me str | None

User's "About Me" description.

None
fave_colors str | None

User's favorite colors.

None
fave_curse str | None

User's favorite curse word.

None
location str | None

User's location.

None

Returns:

Name Type Description
UserFullModel UserModel

The updated user profile.

Source code in src/pyravelry/endpoints/people.py
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
@validate_call
def update(
    self,
    username: str,
    first_name: str | None = None,
    about_me: str | None = None,
    fave_colors: str | None = None,
    fave_curse: str | None = None,
    location: str | None = None,
) -> UserModel:
    """
    Update a user's profile. Requires profile-write permission.

    Args:
        username (str): Username or integer ID of the user to update.
        first_name (str | None): User's first name.
        about_me (str | None): User's "About Me" description.
        fave_colors (str | None): User's favorite colors.
        fave_curse (str | None): User's favorite curse word.
        location (str | None): User's location.

    Returns:
        UserFullModel: The updated user profile.
    """
    update_data = {
        "first_name": first_name,
        "about_me": about_me,
        "fave_colors": fave_colors,
        "fave_curse": fave_curse,
        "location": location,
    }

    payload = UserPostModel(**update_data).model_dump(exclude_unset=True)

    response_dict = self._fetch(self._http.post(self.actions.update.url.format(username), json=payload))

    return cast(UserModel, self.actions.update.model.model_validate(response_dict))

pyravelry.endpoints.SearchResource

Bases: BaseEndpoint

Search endpoint for Ravelry.

Search Ravelry API documentation

Source code in src/pyravelry/endpoints/search.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
class SearchResource(BaseEndpoint):
    """Search endpoint for Ravelry.

    [Search Ravelry API documentation](https://www.ravelry.com/api#/_search)
    """

    actions = TypedNamespace(
        query=Action("/search.json", GlobalSearchResponseModel),
    )

    @validate_call
    def query(
        self,
        query: str,
        limit: int = 10,
        types: Optional[
            list[
                Literal[
                    "User",
                    "PatternAuthor",
                    "PatternSource",
                    "Pattern",
                    "YarnCompany",
                    "Yarn",
                    "Group",
                    "Event",
                    "Project",
                    "Page",
                    "Topic",
                    "Shop",
                ]
            ]
            | None
        ] = None,
    ) -> GlobalSearchResponseModel:
        """
        Perform a global search.

        Args:
            query (str): Any fulltext string
            limit (int): integer between 1 and 50
            types (str|list): Optional. space delineated string or list of strings
                for the types of categories that you are searching.
                See client.search.param_model.model_json_schema()
                for available types.

        Usage:
            search.query(query="merino", limit=10, types=["Yarn"])
        """
        params_obj = SearchParams(query=query, limit=limit, types=types)

        # Flatten the 'types' list into a space-delimited string
        params_dict = params_obj.model_dump(exclude_none=True)

        if "types" in params_dict:
            params_dict["types"] = " ".join(params_dict["types"])

        response_dict = self._fetch(self._http.get(self.actions.query.url, params=params_dict))

        return cast(GlobalSearchResponseModel, self.actions.query.model.model_validate(response_dict))

pyravelry.endpoints.SearchResource.query(query, limit=10, types=None)

Perform a global search.

Parameters:

Name Type Description Default
query str

Any fulltext string

required
limit int

integer between 1 and 50

10
types str | list

Optional. space delineated string or list of strings for the types of categories that you are searching. See client.search.param_model.model_json_schema() for available types.

None
Usage

search.query(query="merino", limit=10, types=["Yarn"])

Source code in src/pyravelry/endpoints/search.py
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
@validate_call
def query(
    self,
    query: str,
    limit: int = 10,
    types: Optional[
        list[
            Literal[
                "User",
                "PatternAuthor",
                "PatternSource",
                "Pattern",
                "YarnCompany",
                "Yarn",
                "Group",
                "Event",
                "Project",
                "Page",
                "Topic",
                "Shop",
            ]
        ]
        | None
    ] = None,
) -> GlobalSearchResponseModel:
    """
    Perform a global search.

    Args:
        query (str): Any fulltext string
        limit (int): integer between 1 and 50
        types (str|list): Optional. space delineated string or list of strings
            for the types of categories that you are searching.
            See client.search.param_model.model_json_schema()
            for available types.

    Usage:
        search.query(query="merino", limit=10, types=["Yarn"])
    """
    params_obj = SearchParams(query=query, limit=limit, types=types)

    # Flatten the 'types' list into a space-delimited string
    params_dict = params_obj.model_dump(exclude_none=True)

    if "types" in params_dict:
        params_dict["types"] = " ".join(params_dict["types"])

    response_dict = self._fetch(self._http.get(self.actions.query.url, params=params_dict))

    return cast(GlobalSearchResponseModel, self.actions.query.model.model_validate(response_dict))

pyravelry.endpoints.YarnAttributesResource

Bases: BaseEndpoint

Endpoint for Color Families.

Attributes:

Name Type Description
BaseEndpoint AnyUrl

The endpoint for yarn attributes.

Methods:

Name Description
list

returns all yarn attributes.

Yarn Attributes Ravelry API documentation

Source code in src/pyravelry/endpoints/yarn_attributes.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class YarnAttributesResource(BaseEndpoint):
    """Endpoint for Color Families.

    Attributes:
        BaseEndpoint (AnyUrl): The endpoint for yarn attributes.

    Methods:
        list (list[YarnAttributeModel]): returns all yarn attributes.

    [Yarn Attributes Ravelry API documentation](https://www.ravelry.com/api#yarn_attributes_list)
    """

    actions = TypedNamespace(list=Action("/yarn_attributes/groups.json", YarnAttributesModel))

    def list(self) -> YarnAttributesModel:
        """
        List the current yarn attributes.

        Endpoint: GET /yarn_attributes/groups.json
        """
        response_dict = self._fetch(self._http.get(self.actions.list.url))
        return cast(YarnAttributesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.YarnAttributesResource.list()

List the current yarn attributes.

Endpoint: GET /yarn_attributes/groups.json

Source code in src/pyravelry/endpoints/yarn_attributes.py
21
22
23
24
25
26
27
28
def list(self) -> YarnAttributesModel:
    """
    List the current yarn attributes.

    Endpoint: GET /yarn_attributes/groups.json
    """
    response_dict = self._fetch(self._http.get(self.actions.list.url))
    return cast(YarnAttributesModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.YarnCompaniesResource

Bases: BaseEndpoint

Endpoint for yarn company specific operations.

Yarn Companies Ravelry API documentation

Source code in src/pyravelry/endpoints/yarn_companies.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
class YarnCompaniesResource(BaseEndpoint):
    """
    Endpoint for yarn company specific operations.

    [Yarn Companies Ravelry API documentation](https://www.ravelry.com/api#yarn_companies_search)
    """

    actions = TypedNamespace(query=Action("/yarn_companies/search.json", YarnCompanySearchResponseModel))

    @validate_call
    def query(
        self,
        query: Optional[str] = None,
        page: int = 1,
        page_size: int = 48,
        sort: str = "best",
    ) -> YarnCompanySearchResponseModel:
        """
        Search the yarn company directory.

        Args:
            query: Search term for fulltext searching.
            page: Result page to retrieve.
            page_size: Number of results per page.
            sort: Sort order (e.g., 'best', 'best_'; reverse order with _ suffix)
        """
        params = YarnCompanySearchParams(query=query, page=page, page_size=page_size, sort=sort)

        response_dict = self._fetch(self._http.get(self.actions.query.url, params=params.model_dump(exclude_none=True)))

        return cast(YarnCompanySearchResponseModel, self.actions.query.model.model_validate(response_dict))

pyravelry.endpoints.YarnCompaniesResource.query(query=None, page=1, page_size=48, sort='best')

Search the yarn company directory.

Parameters:

Name Type Description Default
query str | None

Search term for fulltext searching.

None
page int

Result page to retrieve.

1
page_size int

Number of results per page.

48
sort str

Sort order (e.g., 'best', 'best_'; reverse order with _ suffix)

'best'
Source code in src/pyravelry/endpoints/yarn_companies.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@validate_call
def query(
    self,
    query: Optional[str] = None,
    page: int = 1,
    page_size: int = 48,
    sort: str = "best",
) -> YarnCompanySearchResponseModel:
    """
    Search the yarn company directory.

    Args:
        query: Search term for fulltext searching.
        page: Result page to retrieve.
        page_size: Number of results per page.
        sort: Sort order (e.g., 'best', 'best_'; reverse order with _ suffix)
    """
    params = YarnCompanySearchParams(query=query, page=page, page_size=page_size, sort=sort)

    response_dict = self._fetch(self._http.get(self.actions.query.url, params=params.model_dump(exclude_none=True)))

    return cast(YarnCompanySearchResponseModel, self.actions.query.model.model_validate(response_dict))

pyravelry.endpoints.YarnWeightsResource

Bases: BaseEndpoint

Endpoint for Color Families.

Attributes:

Name Type Description
BaseEndpoint AnyUrl

The endpoint for yarn weights.

Methods:

Name Description
list

returns all yarn weights.

Yarn Weights Ravelry API documentation

Source code in src/pyravelry/endpoints/yarn_weights.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class YarnWeightsResource(BaseEndpoint):
    """Endpoint for Color Families.

    Attributes:
        BaseEndpoint (AnyUrl): The endpoint for yarn weights.

    Methods:
        list (list[YarnWeightModel]): returns all yarn weights.

    [Yarn Weights Ravelry API documentation](https://www.ravelry.com/api#/_yarn_weights)
    """

    actions = TypedNamespace(list=Action("/yarn_weights.json", YarnWeightsModel))

    def list(self) -> YarnWeightsModel:
        """
        List the current yarn weights.

        Endpoint: GET /yarn_weights.json
        """
        response_dict = self._fetch(self._http.get(self.actions.list.url))
        return cast(YarnWeightsModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.YarnWeightsResource.list()

List the current yarn weights.

Endpoint: GET /yarn_weights.json

Source code in src/pyravelry/endpoints/yarn_weights.py
21
22
23
24
25
26
27
28
def list(self) -> YarnWeightsModel:
    """
    List the current yarn weights.

    Endpoint: GET /yarn_weights.json
    """
    response_dict = self._fetch(self._http.get(self.actions.list.url))
    return cast(YarnWeightsModel, self.actions.list.model.model_validate(response_dict))

pyravelry.endpoints.YarnsResource

Bases: BaseEndpoint

Yarns endpoint for Ravelry.

Handles yarn searches, yarn details, batch fetches, and comments.

Yarn Ravelry API documentation

Source code in src/pyravelry/endpoints/yarn.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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class YarnsResource(BaseEndpoint):
    """Yarns endpoint for Ravelry.

    Handles yarn searches, yarn details, batch fetches, and comments.

    [Yarn Ravelry API documentation](https://www.ravelry.com/api#yarns_comments)
    """

    actions = TypedNamespace(
        comments=Action("/yarns/{}/comments.json", YarnResponseComments),
        search=Action("/yarns/search.json", YarnResponseSearch),
        show=Action("/yarns/{}.json", YarnResponseShow),
        yarns=Action("/yarns.json", YarnResponseYarns),
    )

    @validate_call
    def comments(
        self,
        id_: int,
        page: Optional[int] = None,
        page_size: Optional[int] = None,
        sort: Optional[Literal["time", "helpful", "time_", "helpful_"]] = None,
        include: Optional[str] = None,
    ) -> YarnResponseComments:
        """
        Retrieve a yarn's comments.

        Args:
            id_ (int): Yarn ID to retrieve comments for.
            page (int | None): Result page to retrieve. Defaults to first page.
            page_size (int | None): Defaults to 25 comments per page. Maximum is 100.
            sort (str | None): Sort order options: time, helpful, time_, helpful_.
            include (str | None): Space-delimited extra results. e.g. "highlighted_project".

        Returns:
            YarnResponseComments: Comments associated with this type of yarn.
        """

        params = {
            "page": page,
            "page_size": page_size,
            "sort": sort,
            "include": include,
        }
        params = {k: v for k, v in params.items() if v is not None}

        response_dict = self._fetch(self._http.get(self.actions.comments.url.format(id_), params=params))
        transformed_dict = self._validate(response_dict, self.actions.comments)
        return cast(YarnResponseComments, self.actions.comments.model.model_validate(transformed_dict))

    @validate_call
    def search(
        self,
        query: str,
        page: Optional[int] = None,
        page_size: Optional[int] = None,
        sort: Optional[Literal["best", "rating", "projects"]] = None,
        personal_attributes: Optional[bool] = None,
    ) -> YarnResponseSearch:
        """
        Search yarn database.

        Args:
            query (str): Search term for fulltext searching yarns.
            page (int | None): Result page to retrieve. Defaults to first page.
            page_size (int | None): Defaults to 50 results per page.
            sort (str | None): Sort order options: best, rating, projects.
            personal_attributes (bool | None): Set to True (returns 1) to fetch personal data hashes.

        Returns:
            YarnResponseSearch: search results with pagination information.
        """
        params = {
            "query": query,
            "page": page,
            "page_size": page_size,
            "sort": sort,
            "personal_attributes": 1 if personal_attributes else 0,
        }
        params = {k: v for k, v in params.items() if v is not None}

        response_dict = self._fetch(self._http.get(self.actions.search.url, params=params))
        transformed_dict = self._validate(response_dict, self.actions.search)
        return cast(YarnResponseSearch, self.actions.search.model.model_validate(transformed_dict))

    @validate_call
    def show(self, id_: int, include: Optional[str] = None) -> YarnResponseShow:
        """
        Get yarn details.

        Args:
            id_ (int): Yarn ID to retrieve.
            include (str | None): Space-delimited extra results. Accepted: "colorways", "availability".

        Returns:
            YarnResponseShow: pydantic model of yarn ids and data
        """
        params = {"include": include} if include else {}

        response_dict = self._fetch(self._http.get(self.actions.show.url.format(id_), params=params))

        transformed_dict = self._validate(response_dict, self.actions.show)
        return cast(YarnResponseShow, self.actions.show.model.model_validate(transformed_dict))

    @validate_call
    def yarns(self, ids: list[int]) -> YarnResponseYarns:
        """
        Get yarn details for multiple yarns.

        Args:
            ids (list[int]): List of yarn IDs to retrieve.

        Returns:
            dict[int, YarnFullModel]: Map of YarnFullModel results, indexed by yarn ID.
        """
        # Formulate space-delimited string as required (e.g., 600+601 handling via HTTP layers or raw string join)
        space_delimited_ids = " ".join(map(str, ids))
        params = {"ids": space_delimited_ids}

        response_dict = self._fetch(self._http.get(self.actions.yarns.url, params=params))

        return cast(YarnResponseYarns, self.actions.yarns.model.model_validate(response_dict))

pyravelry.endpoints.YarnsResource.comments(id_, page=None, page_size=None, sort=None, include=None)

Retrieve a yarn's comments.

Parameters:

Name Type Description Default
id_ int

Yarn ID to retrieve comments for.

required
page int | None

Result page to retrieve. Defaults to first page.

None
page_size int | None

Defaults to 25 comments per page. Maximum is 100.

None
sort str | None

Sort order options: time, helpful, time_, helpful_.

None
include str | None

Space-delimited extra results. e.g. "highlighted_project".

None

Returns:

Name Type Description
YarnResponseComments YarnResponseComments

Comments associated with this type of yarn.

Source code in src/pyravelry/endpoints/yarn.py
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
@validate_call
def comments(
    self,
    id_: int,
    page: Optional[int] = None,
    page_size: Optional[int] = None,
    sort: Optional[Literal["time", "helpful", "time_", "helpful_"]] = None,
    include: Optional[str] = None,
) -> YarnResponseComments:
    """
    Retrieve a yarn's comments.

    Args:
        id_ (int): Yarn ID to retrieve comments for.
        page (int | None): Result page to retrieve. Defaults to first page.
        page_size (int | None): Defaults to 25 comments per page. Maximum is 100.
        sort (str | None): Sort order options: time, helpful, time_, helpful_.
        include (str | None): Space-delimited extra results. e.g. "highlighted_project".

    Returns:
        YarnResponseComments: Comments associated with this type of yarn.
    """

    params = {
        "page": page,
        "page_size": page_size,
        "sort": sort,
        "include": include,
    }
    params = {k: v for k, v in params.items() if v is not None}

    response_dict = self._fetch(self._http.get(self.actions.comments.url.format(id_), params=params))
    transformed_dict = self._validate(response_dict, self.actions.comments)
    return cast(YarnResponseComments, self.actions.comments.model.model_validate(transformed_dict))

pyravelry.endpoints.YarnsResource.search(query, page=None, page_size=None, sort=None, personal_attributes=None)

Search yarn database.

Parameters:

Name Type Description Default
query str

Search term for fulltext searching yarns.

required
page int | None

Result page to retrieve. Defaults to first page.

None
page_size int | None

Defaults to 50 results per page.

None
sort str | None

Sort order options: best, rating, projects.

None
personal_attributes bool | None

Set to True (returns 1) to fetch personal data hashes.

None

Returns:

Name Type Description
YarnResponseSearch YarnResponseSearch

search results with pagination information.

Source code in src/pyravelry/endpoints/yarn.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@validate_call
def search(
    self,
    query: str,
    page: Optional[int] = None,
    page_size: Optional[int] = None,
    sort: Optional[Literal["best", "rating", "projects"]] = None,
    personal_attributes: Optional[bool] = None,
) -> YarnResponseSearch:
    """
    Search yarn database.

    Args:
        query (str): Search term for fulltext searching yarns.
        page (int | None): Result page to retrieve. Defaults to first page.
        page_size (int | None): Defaults to 50 results per page.
        sort (str | None): Sort order options: best, rating, projects.
        personal_attributes (bool | None): Set to True (returns 1) to fetch personal data hashes.

    Returns:
        YarnResponseSearch: search results with pagination information.
    """
    params = {
        "query": query,
        "page": page,
        "page_size": page_size,
        "sort": sort,
        "personal_attributes": 1 if personal_attributes else 0,
    }
    params = {k: v for k, v in params.items() if v is not None}

    response_dict = self._fetch(self._http.get(self.actions.search.url, params=params))
    transformed_dict = self._validate(response_dict, self.actions.search)
    return cast(YarnResponseSearch, self.actions.search.model.model_validate(transformed_dict))

pyravelry.endpoints.YarnsResource.show(id_, include=None)

Get yarn details.

Parameters:

Name Type Description Default
id_ int

Yarn ID to retrieve.

required
include str | None

Space-delimited extra results. Accepted: "colorways", "availability".

None

Returns:

Name Type Description
YarnResponseShow YarnResponseShow

pydantic model of yarn ids and data

Source code in src/pyravelry/endpoints/yarn.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@validate_call
def show(self, id_: int, include: Optional[str] = None) -> YarnResponseShow:
    """
    Get yarn details.

    Args:
        id_ (int): Yarn ID to retrieve.
        include (str | None): Space-delimited extra results. Accepted: "colorways", "availability".

    Returns:
        YarnResponseShow: pydantic model of yarn ids and data
    """
    params = {"include": include} if include else {}

    response_dict = self._fetch(self._http.get(self.actions.show.url.format(id_), params=params))

    transformed_dict = self._validate(response_dict, self.actions.show)
    return cast(YarnResponseShow, self.actions.show.model.model_validate(transformed_dict))

pyravelry.endpoints.YarnsResource.yarns(ids)

Get yarn details for multiple yarns.

Parameters:

Name Type Description Default
ids list[int]

List of yarn IDs to retrieve.

required

Returns:

Type Description
YarnResponseYarns

dict[int, YarnFullModel]: Map of YarnFullModel results, indexed by yarn ID.

Source code in src/pyravelry/endpoints/yarn.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@validate_call
def yarns(self, ids: list[int]) -> YarnResponseYarns:
    """
    Get yarn details for multiple yarns.

    Args:
        ids (list[int]): List of yarn IDs to retrieve.

    Returns:
        dict[int, YarnFullModel]: Map of YarnFullModel results, indexed by yarn ID.
    """
    # Formulate space-delimited string as required (e.g., 600+601 handling via HTTP layers or raw string join)
    space_delimited_ids = " ".join(map(str, ids))
    params = {"ids": space_delimited_ids}

    response_dict = self._fetch(self._http.get(self.actions.yarns.url, params=params))

    return cast(YarnResponseYarns, self.actions.yarns.model.model_validate(response_dict))