aioe621 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aioe621/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .client import Client
2
+ from .schemas import Auth
3
+
4
+ __all__ = ["Client", "Auth"]
aioe621/client.py ADDED
@@ -0,0 +1,61 @@
1
+ import base64
2
+ import typing
3
+
4
+ import httpx
5
+ from pydantic import BaseModel
6
+
7
+ from .endpoints.posts import Posts
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from .schemas import Auth
11
+
12
+
13
+ class Client:
14
+ E621_BASE_URL = "https://e621.net"
15
+ E926_BASE_URL = "https://e926.net"
16
+
17
+ def __init__(
18
+ self,
19
+ auth: "Auth",
20
+ base_url: str = E621_BASE_URL,
21
+ user_agent: str | None = None,
22
+ session: httpx.AsyncClient | None = None,
23
+ **session_kwargs,
24
+ ) -> None:
25
+ self.auth = auth
26
+ self.user_agent = user_agent or "penggrin12/aioe621@github penggrin@telegram"
27
+ self.session = session or httpx.AsyncClient(base_url=base_url, **session_kwargs)
28
+
29
+ self.posts = Posts(self)
30
+
31
+ def _get_auth_header_value(self) -> str:
32
+ return base64.b64encode(
33
+ f"{self.auth.username}:{self.auth.api_key}".encode()
34
+ ).decode()
35
+
36
+ async def _request(
37
+ self, method: str, url: str, *, authorized: bool = False, **params
38
+ ) -> str:
39
+ response = await self.session.request(
40
+ method,
41
+ url,
42
+ params={k: v for k, v in params.items() if v is not None},
43
+ headers={
44
+ "User-Agent": self.user_agent,
45
+ **(
46
+ {"Authorization": self._get_auth_header_value()}
47
+ if authorized
48
+ else {}
49
+ ),
50
+ },
51
+ )
52
+ return response.text
53
+
54
+ _MT = typing.TypeVar("_MT", bound="BaseModel")
55
+
56
+ async def _request_model(
57
+ self, model: type[_MT], method: str, url: str, **kwargs
58
+ ) -> _MT:
59
+ return model.model_validate_json(
60
+ await self._request(method=method, url=url, **kwargs)
61
+ )
File without changes
@@ -0,0 +1,12 @@
1
+ import typing
2
+
3
+ if typing.TYPE_CHECKING:
4
+ from ..client import Client
5
+
6
+
7
+ class Endpoint:
8
+ def __init__(self, client: "Client") -> None:
9
+ self._client = client
10
+
11
+ self._request = client._request
12
+ self._request_model = self._client._request_model
@@ -0,0 +1,47 @@
1
+ from ..schemas import Post, _PostsListResponse, _PostsOnePostResponse
2
+ from .endpoint import Endpoint
3
+
4
+
5
+ class Posts(Endpoint):
6
+ async def list(
7
+ self,
8
+ tags: list[str] | str,
9
+ limit: int | None = None,
10
+ page: int | None = None,
11
+ ) -> list[Post]:
12
+ if isinstance(tags, list):
13
+ tags = " ".join(tags)
14
+
15
+ return (
16
+ await self._request_model(
17
+ _PostsListResponse,
18
+ "GET",
19
+ "/posts.json",
20
+ tags=tags,
21
+ limit=limit,
22
+ page=page,
23
+ )
24
+ ).posts
25
+
26
+ async def get(
27
+ self,
28
+ id: int,
29
+ ) -> Post:
30
+ return (
31
+ await self._request_model(
32
+ _PostsOnePostResponse,
33
+ "GET",
34
+ f"/posts/{id}.json",
35
+ )
36
+ ).post
37
+
38
+ async def random(
39
+ self,
40
+ ) -> Post:
41
+ return (
42
+ await self._request_model(
43
+ _PostsOnePostResponse,
44
+ "GET",
45
+ "/posts/random.json",
46
+ )
47
+ ).post
aioe621/py.typed ADDED
File without changes
aioe621/schemas.py ADDED
@@ -0,0 +1,128 @@
1
+ from datetime import datetime
2
+ from enum import Enum
3
+ from typing import NamedTuple
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+
8
+ class Auth(NamedTuple):
9
+ username: str
10
+ api_key: str
11
+
12
+
13
+ class BaseFile(BaseModel):
14
+ width: int
15
+ height: int
16
+ url: str | None = None # Safest to make URL optional (deleted posts hide URLs)
17
+
18
+
19
+ class File(BaseFile):
20
+ ext: str
21
+ size: int
22
+ md5: str
23
+
24
+
25
+ class PreviewFile(BaseFile):
26
+ alt: str | None = None
27
+
28
+
29
+ class VideoAlternate(BaseModel):
30
+ fps: int
31
+ codec: str
32
+ size: int
33
+ width: int
34
+ height: int
35
+ url: str | None = None
36
+
37
+
38
+ class Alternates(BaseModel):
39
+ has: bool = False
40
+ original: VideoAlternate | None = None
41
+ variants: dict[str, VideoAlternate] = Field(default_factory=dict)
42
+ samples: dict[str, VideoAlternate] = Field(default_factory=dict)
43
+
44
+
45
+ class SampleFile(PreviewFile):
46
+ has: bool
47
+ alternates: Alternates
48
+
49
+
50
+ class PostScore(BaseModel):
51
+ up: int
52
+ down: int
53
+ total: int
54
+
55
+
56
+ class PostTags(BaseModel):
57
+ general: list[str]
58
+ artist: list[str]
59
+ contributor: list[str]
60
+ copyright: list[str]
61
+ character: list[str]
62
+ species: list[str]
63
+ invalid: list[str]
64
+ meta: list[str]
65
+ lore: list[str]
66
+
67
+
68
+ class PostFlags(BaseModel):
69
+ pending: bool
70
+ flagged: bool
71
+ note_locked: bool
72
+ status_locked: bool
73
+ rating_locked: bool
74
+ deleted: bool
75
+
76
+
77
+ class Rating(str, Enum):
78
+ SAFE = "s"
79
+ QUESTIONABLE = "q"
80
+ EXPLICIT = "e"
81
+
82
+
83
+ class Relationships(BaseModel):
84
+ parent_id: int | None = None
85
+ has_children: bool
86
+ has_active_children: bool
87
+ children: list[int]
88
+
89
+
90
+ class Post(BaseModel):
91
+ id: int
92
+ created_at: datetime
93
+ updated_at: datetime
94
+
95
+ file: File
96
+ preview: PreviewFile
97
+ sample: SampleFile
98
+
99
+ score: PostScore
100
+ tags: PostTags
101
+ locked_tags: list[str]
102
+ change_seq: int
103
+ flags: PostFlags
104
+ rating: Rating
105
+
106
+ fav_count: int
107
+ sources: list[str]
108
+ pools: list[int]
109
+ relationships: Relationships
110
+
111
+ approver_id: int | None = None
112
+ uploader_id: int
113
+ uploader_name: str
114
+ description: str
115
+ comment_count: int
116
+ is_favorited: bool
117
+
118
+ vote: int
119
+ has_notes: bool
120
+ duration: float | None = None
121
+
122
+
123
+ class _PostsListResponse(BaseModel):
124
+ posts: list[Post]
125
+
126
+
127
+ class _PostsOnePostResponse(BaseModel):
128
+ post: Post
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.3
2
+ Name: aioe621
3
+ Version: 0.1.0
4
+ Summary: A simple asynchronous httpx+pydantic wrapper over the E621's API
5
+ Keywords: async,httpx,e621
6
+ Author: penggrin12
7
+ Author-email: penggrin12 <miner.sidor@gmail.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 penggrin12
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ Classifier: Framework :: AsyncIO
30
+ Classifier: Framework :: Pydantic
31
+ Classifier: Programming Language :: Python
32
+ Classifier: Programming Language :: Python :: 3
33
+ Classifier: Programming Language :: Python :: 3.10
34
+ Classifier: Programming Language :: Python :: 3.11
35
+ Classifier: Programming Language :: Python :: 3.12
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Programming Language :: Python :: 3.14
38
+ Classifier: Typing :: Typed
39
+ Requires-Dist: httpx>=0.28.1
40
+ Requires-Dist: orjson>=3.11.9
41
+ Requires-Dist: pydantic>=2.13.4
42
+ Requires-Python: >=3.10
@@ -0,0 +1,10 @@
1
+ aioe621/__init__.py,sha256=PdoDRkoDn5K74gdkc5zHQ0CZYDE058_kGwqd4EnzrPk,83
2
+ aioe621/client.py,sha256=-xmL4qYMB60gfeuKNl16bEZRoFYBAqsp4j_N0b4HBZU,1724
3
+ aioe621/endpoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ aioe621/endpoints/endpoint.py,sha256=MbDkwfGk6TJZCXCCTvcDZyoQSN5y8r1aBh8vgzL6lXM,272
5
+ aioe621/endpoints/posts.py,sha256=mqn3OcihXjX4YbcqUi9QfTl0iCt5zMxqw1MLWaG7x9g,1098
6
+ aioe621/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ aioe621/schemas.py,sha256=xqeW0zYp9ECzah02g9c4qdobyyAZL9eP9cY2bCnnuiY,2295
8
+ aioe621-0.1.0.dist-info/WHEEL,sha256=CoDSoyhtC_eO_tlxRYzsTraPv1fPJRXFx91k6ISeAvA,81
9
+ aioe621-0.1.0.dist-info/METADATA,sha256=2fqQpDkbTNbkLbQD50GsAOE4yCUYPmF6HXg3cGJf--s,2032
10
+ aioe621-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.11.28
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any