Skip to main content

A simple asynchronous httpx+pydantic wrapper over the E621's API

Project description

aioe621 GitHub Tag

uv PyPI Python Version

GitHub License GitHub Actions Workflow Status

A simple asynchronous httpx+pydantic wrapper over the e621 API.

The library API is considered unstable until version 1.0.0. Minor releases may include breaking changes.

Quickstart

from aioe621 import Client
from aioe621.schemas.posts import Post
import asyncio

# a user agent is required
client = Client(user_agent="MyProject/1.0 (by username on e621)")


async def main() -> None:
    post: Post = await client.posts.get(5937863)
    print(f"i love {post.tags.artist[0]}!!!")


asyncio.run(main())

Installation

pip install aioe621

or using uv (recommended):

uv add aioe621

TagSet

TagSet is a small query-building helper around e621's tag syntax. It behaves mostly like a normal set[str], but adds convenient methods for composing searches.

Using TagSet is not required. All endpoints that accept tags also work with other "Tag"-like or "Tag list"-like types (including plain strings and iterables of strings). TagSet is provided as a convenience for building, combining, and reusing complex queries.

Build searches fluently

# find posts by the same artists, but include a specific feature
query = post.tags.artist.with_tag("tail")
print(str(query))  # cool_artist tail
posts = await client.posts.list(tags=query)

Exclude tags

Negated tags are useful for filtering out things you don't want:

# with the same species, but no humans
# each list item here is like a blacklist line in e621
query = post.tags.species.with_blacklist(["human"])
# or you could just do .with_tag("-human")

Which for a post of a dog with a cat produces the equivalent of canine feline -human

Combine tag groups

Tag groups can be merged together:

# search for the characters of the specific artists and copyrights
query = post.tags.character + post.tags.species + post.tags.copyright

Build reusable search presets

Because TagSet is composable, you can keep common searches around:

from aioe621.objects import TagSet
from aioe621.enums import PostRating

anthro_pups_with_fangs = TagSet({"fangs", "canine", "-feral"})
rating = PostRating.SAFE  # just "s" or "safe" also works!

favorites = anthro_pups_with_fangs.with_rating(rating)

All TagSet methods

Method Purpose
+ Combine tag groups
with_tag() Add a tag
with_tags() Add multiple tags
with_blacklist() Add and negate lists of TagSet, like the e621 blacklist
negate() Negate tags
with_order() Add search ordering
with_rating() Add search rating
flatten() Flatten into a str

Schema helpers

Some schema objects provide small helper methods that use the attached client to fetch related resources.

Post

# get posts that have this post as their parent
children: Sequence[Post] = await post.fetch_children()

# get the parent if it has one
parent: Post | None = await post.fetch_parent()

Pool

pool = await client.pools.get(12345)

# this is only the ids
print(pool.post_ids)  # [69420, 42069, ...]

# fetch the full Post objects
posts: list[Post] = await pool.fetch_posts()

print(posts[0].rating)  # PostRating.EXPLICIT

Currently implemented API endpoints

e621 API aioe621
GET /posts.json .posts.list
GET /posts/{id}.json .posts.get
GET /posts/random.json .posts.random
GET /popular.json .posts.popular
GET /tags.json .tags.list and tags.get_by_name
GET /tags/{id}.json .tags.get
GET /pools.json .pools.list
GET /pools/{id}.json .pools.get
GET /forum_posts.json .forum.posts
GET /forum_posts/{id}.json .forum.post
GET /forum_topics.json .forum.topics
GET /forum_topics/{id}.json .forum.topic

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

aioe621-0.9.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

aioe621-0.9.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file aioe621-0.9.0.tar.gz.

File metadata

  • Download URL: aioe621-0.9.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aioe621-0.9.0.tar.gz
Algorithm Hash digest
SHA256 28e7fb4f52298982e8e8e90ca0c93c97dfa70446107a8c0c6bb1dc32d177d18d
MD5 9b748a7a69387b4fab9b7dd4a62d2794
BLAKE2b-256 7486dd2ecd11d753cf69122fa62fe683767060dbd9cc495a7d2867fe26679520

See more details on using hashes here.

File details

Details for the file aioe621-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: aioe621-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aioe621-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5468569174ff5449be50a48a46ac3403cf0c84175c893a95f31efba8346b6ca
MD5 0226e822a1a499d46dbe26e82b03cc75
BLAKE2b-256 cff2d289bddabaecc2700204839ade49fcaeb7b014a6d827ddaf04b98d8f3ff1

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