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: Post) -> list[Comments]
    Fetch the comments of a post.

Parameters

post: Post
    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: Post
    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.2.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.2.1-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyr34-0.2.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.2.1.tar.gz
Algorithm Hash digest
SHA256 d7ee9405dbe2b86e2b08df03fe57af2e964e7a802ece6ebf48b1e05a62490d91
MD5 6a233dd8431a76f4dec3ad8d65f92efb
BLAKE2b-256 0a43f17b880b49039573bc90d4296791e1080ede72ef231f44d735fa33ed2d7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyr34-0.2.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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef45e2f656b4afe901501b50db219a6c3ad3add163264678d90d72a73338418a
MD5 61608c307f66b661f3bb1b83381e4004
BLAKE2b-256 4683fc2cebf700f4bb954b9e28198f0a5087cb60cdbd70a731994accd71e3bca

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