Skip to main content

Wrapper around the JSON/XML rule34.xxx API.

Project description

pyr34

Wrapper around the JSON/XML rule34.xxx API.

Classes

ClientAPI

Represents a connection to the R34 API.
Central component of the library. Handles all communication to and from the API.

Parameters

user_id: int
    The ID of the user associated with the API key

api_key: str
    The API key used to authenticate the R34 API

url: str, optional (keyword-only)
    Base URL for the API, should be an index.php.
    If omitted, https://api.rule34.xxx/index.php is used.

base_url: str, optional (keyword-only)
    Base URL for the website
    If omitted, https://rule34.xxx/ is used.


Methods

search_posts(tags: Tag | str = Tag(), *, limit: int = 1000, exclusions: list[Tag] | list[str] | None = None, page: int = 0, suppress_log: bool = False) -> Generator[Post]
    Search for posts via standard search tags.

Parameters

tags: Tag or str, optional
    Tags to search for.
    If omitted, pull from the front page.

limit: int, optional (keyword-only)
    Maximum number of posts to pull.
    If omitted, pull the maximum allowed (1000).

exclusions: list[Tag] or list[str], optional (keyword-only)
    Tags to exclude from search.

page: int, optional (keyword-only)
    Page of results to return.
    If omitted, return first page.

suppress_log: bool, optional (keyword-only)
    Don't log search. Intended for internal use.

Returns

Generator that yields fetched Posts.

Notes

    Logs search at INFO level.
    Excluding tags using tags is allowed, but discouraged due to R34 quirks.


get_post(id: int) -> Post
    Fetch a post by ID.

Parameters

id: int
    ID of the post to fetch.

Returns

    Post
    The fetched post.

Notes

    Logs fetch at INFO level.


get_comments(post_id: int) -> list[Comments]
    Fetch the comments of a post.

Parameters

post_id: int
    ID of the post to fetch comments from.

Returns

list[Comment]
    List of fetched comments.

Notes

    Logs fetch at INFO level.


request(params: Mapping[str, Any]) -> ET.Element | Any | None
    Make a generic request to the API.
    Usage is discouraged, as input validation and error handling is minimal.

Returns

    xml.etree.ElementTree.Element or Any
    XML parsed as an Element, or JSON parsed into Python objects.

Notes

    Logs API request at INFO level.
    Returns None for empty responses / malformed requests.


Post

Represents a post.

Attributes

id: int
    ID of the post.

tags: list[Tag]
    List of post's tags.

author: str
    User who created the post.

source: str
    Where the post came from.

score: int
    Post's score.

rating: Rating
    Safe, Questionable, or Explicit.

last_change: datetime.datetime
    Timestamp of the post's last edit in UTC.

content_url: str
    URL of the post's image.

comments: list[Comment]
    Lazy-loaded list of comments.


Methods

get_comments() -> list[Comment]
    Fetch post's comments in real-time.

get_url() -> str
    URL of post given the base URL provided to ClientAPI.


Comment

Represents a comment.

Attributes

id: int
    ID of the comment.

post_id: int
    ID of the post the comment is under.

content: str
    Content of the comment.

author: str
    Creator of the comment.

created_at: datetime.datetime
    Timestamp of the comment's creation in UTC.


Rating (Enum)

Safe, Questionable, or Explicit.

Class Methods

str_to_rating(rating: str) -> Rating
    Maps "safe", "questionable", and "explicit" to enum values.

rating_to_str(rating: Rating) -> str
    Maps enum values to "safe", "questionable", and "explicit".


Tag

Represents a tag.
Utilizes a DSL-like system of combining Tag objects.

Operators

     tag1 & tag2: tag1 tag2
     tag1 | tag2: ( tag1 ~ tag2 )
     tag1 - tag2: tag1 -tag2
     -tag OR ~tag: -tag

Notes

    All binary operators support str inputs for other
    R34 is strange, and several combinations of tags aren't allowed. Don't be surprised if no posts come up.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyr34-0.1.1.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyr34-0.1.1-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file pyr34-0.1.1.tar.gz.

File metadata

  • Download URL: pyr34-0.1.1.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for pyr34-0.1.1.tar.gz
Algorithm Hash digest
SHA256 81cb27cbc4435f958fe194dbcc8e213ea037a25816f98b2ea63e479ea94e759b
MD5 c97d1c4f0b2ffec602f25e5a63222243
BLAKE2b-256 0e754e3d4bbc870610713f9070d6a93c55c87dfc436b658a2f4f1ef5bbb9446f

See more details on using hashes here.

File details

Details for the file pyr34-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyr34-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for pyr34-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2761c77f36ddc8a3a63df382dde1da112c712d84ebc759dca38b522f45fc9b94
MD5 7b4f09bf835fbfd578b932e4d5d787a3
BLAKE2b-256 14dbd4c553a1e2b551d20f01c5b8863b888c59c4139ace16b63c3a45a4ecdd17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page