pixabay-client 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.
- pixabay_client/__init__.py +11 -0
- pixabay_client/_core.py +214 -0
- pixabay_client/client.py +280 -0
- pixabay_client/errors.py +26 -0
- pixabay_client/models.py +128 -0
- pixabay_client/py.typed +0 -0
- pixabay_client-0.1.0.dist-info/METADATA +107 -0
- pixabay_client-0.1.0.dist-info/RECORD +10 -0
- pixabay_client-0.1.0.dist-info/WHEEL +4 -0
- pixabay_client-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""pixabay-client: a typed Pixabay API client that follows Pixabay's API rules for you."""
|
|
2
|
+
from ._core import Cache, MemoryCache
|
|
3
|
+
from .client import AsyncPixabayClient, PixabayClient
|
|
4
|
+
from .errors import AuthError, NotFound, PixabayError, RateLimited, ServiceError
|
|
5
|
+
from .models import Image, RateLimit, Rendition, SearchResult, Video, VideoRendition
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"AsyncPixabayClient", "AuthError", "Cache", "Image", "MemoryCache", "NotFound", "PixabayClient", "PixabayError",
|
|
9
|
+
"RateLimit", "RateLimited", "Rendition", "SearchResult", "ServiceError", "Video", "VideoRendition",
|
|
10
|
+
]
|
|
11
|
+
__version__ = "0.1.0"
|
pixabay_client/_core.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""What the sync and async clients share: parameters, the cache, rate limits, errors and key redaction."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import threading
|
|
9
|
+
import time
|
|
10
|
+
from collections.abc import Callable, Iterable, Mapping
|
|
11
|
+
from typing import Any, Literal, Protocol
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
from .errors import AuthError, NotFound, PixabayError, RateLimited, ServiceError
|
|
16
|
+
from .models import Image, RateLimit, SearchResult, Video
|
|
17
|
+
|
|
18
|
+
API = "https://pixabay.com/api/"
|
|
19
|
+
VIDEO_API = "https://pixabay.com/api/videos/"
|
|
20
|
+
DAY = 24 * 3600
|
|
21
|
+
DOWNLOAD_HOSTS = ("pixabay.com", "cdn.pixabay.com")
|
|
22
|
+
Size = Literal["large", "webformat", "preview"]
|
|
23
|
+
|
|
24
|
+
# Tags that mark a hit as showing people (exclude_people=True). A tag match, not a guarantee.
|
|
25
|
+
PEOPLE_TAGS = frozenset({
|
|
26
|
+
"people", "person", "man", "woman", "men", "women", "girl", "girls", "boy", "boys", "child", "children", "kid",
|
|
27
|
+
"kids", "baby", "human", "humans", "lady", "guy", "couple", "family", "model", "teen", "teenager", "adult",
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Cache(Protocol):
|
|
32
|
+
def get(self, key: str) -> Any | None: ...
|
|
33
|
+
def set(self, key: str, value: Any, ttl: float) -> None: ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class MemoryCache:
|
|
37
|
+
"""A small thread-safe in-memory TTL cache (the default)."""
|
|
38
|
+
|
|
39
|
+
def __init__(self, max_items: int = 1000, clock: Callable[[], float] = time.monotonic) -> None:
|
|
40
|
+
self._items: dict[str, tuple[float, Any]] = {}
|
|
41
|
+
self._max = max_items
|
|
42
|
+
self._clock = clock
|
|
43
|
+
self._lock = threading.Lock()
|
|
44
|
+
|
|
45
|
+
def get(self, key: str) -> Any | None:
|
|
46
|
+
with self._lock:
|
|
47
|
+
item = self._items.get(key)
|
|
48
|
+
if item is None:
|
|
49
|
+
return None
|
|
50
|
+
if item[0] <= self._clock():
|
|
51
|
+
del self._items[key]
|
|
52
|
+
return None
|
|
53
|
+
return item[1]
|
|
54
|
+
|
|
55
|
+
def set(self, key: str, value: Any, ttl: float) -> None:
|
|
56
|
+
with self._lock:
|
|
57
|
+
if len(self._items) >= self._max:
|
|
58
|
+
self._items.pop(next(iter(self._items))) # the oldest
|
|
59
|
+
self._items[key] = (self._clock() + ttl, value)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class _RedactKey(logging.Filter):
|
|
63
|
+
_key = re.compile(r"([?&]key=)[^&\s'\"]+")
|
|
64
|
+
|
|
65
|
+
def filter(self, record: logging.LogRecord) -> bool:
|
|
66
|
+
if record.args:
|
|
67
|
+
record.msg = record.getMessage()
|
|
68
|
+
record.args = None
|
|
69
|
+
if isinstance(record.msg, str):
|
|
70
|
+
record.msg = self._key.sub(r"\1***", record.msg)
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def install_log_redaction() -> None:
|
|
75
|
+
"""httpx logs every request URL, and Pixabay wants the key in the URL: redact it (once per logger)."""
|
|
76
|
+
for name in ("httpx", "httpcore"):
|
|
77
|
+
logger = logging.getLogger(name)
|
|
78
|
+
if not any(isinstance(f, _RedactKey) for f in logger.filters):
|
|
79
|
+
logger.addFilter(_RedactKey())
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def resolve_key(key: str | None) -> str:
|
|
83
|
+
key = key or os.environ.get("PIXABAY_API_KEY", "")
|
|
84
|
+
if not key:
|
|
85
|
+
raise AuthError("No Pixabay API key: pass one or set PIXABAY_API_KEY.")
|
|
86
|
+
return key
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _flag(v: bool) -> str:
|
|
90
|
+
return "true" if v else "false"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def image_params(q: str | None, *, lang: str, image_type: str, orientation: str, category: str | None,
|
|
94
|
+
min_width: int, min_height: int, colors: Iterable[str] | None, editors_choice: bool,
|
|
95
|
+
safesearch: bool, order: str, page: int, per_page: int) -> dict[str, str]:
|
|
96
|
+
p = _shared(q, lang=lang, category=category, min_width=min_width, min_height=min_height,
|
|
97
|
+
editors_choice=editors_choice, safesearch=safesearch, order=order, page=page, per_page=per_page)
|
|
98
|
+
p.update(image_type=image_type, orientation=orientation)
|
|
99
|
+
if colors:
|
|
100
|
+
p["colors"] = ",".join(colors)
|
|
101
|
+
return p
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def video_params(q: str | None, *, lang: str, video_type: str, category: str | None, min_width: int,
|
|
105
|
+
min_height: int, editors_choice: bool, safesearch: bool, order: str, page: int,
|
|
106
|
+
per_page: int) -> dict[str, str]:
|
|
107
|
+
p = _shared(q, lang=lang, category=category, min_width=min_width, min_height=min_height,
|
|
108
|
+
editors_choice=editors_choice, safesearch=safesearch, order=order, page=page, per_page=per_page)
|
|
109
|
+
p["video_type"] = video_type
|
|
110
|
+
return p
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _shared(q: str | None, *, lang: str, category: str | None, min_width: int, min_height: int,
|
|
114
|
+
editors_choice: bool, safesearch: bool, order: str, page: int, per_page: int) -> dict[str, str]:
|
|
115
|
+
if q is not None and len(q) > 100:
|
|
116
|
+
raise ValueError("Pixabay search terms are at most 100 characters.")
|
|
117
|
+
if not 3 <= per_page <= 200:
|
|
118
|
+
raise ValueError("per_page must be between 3 and 200.")
|
|
119
|
+
if page < 1:
|
|
120
|
+
raise ValueError("page starts at 1.")
|
|
121
|
+
p = {"lang": lang, "min_width": str(min_width), "min_height": str(min_height),
|
|
122
|
+
"editors_choice": _flag(editors_choice), "safesearch": _flag(safesearch), "order": order,
|
|
123
|
+
"page": str(page), "per_page": str(per_page)}
|
|
124
|
+
if q:
|
|
125
|
+
p["q"] = q
|
|
126
|
+
if category:
|
|
127
|
+
p["category"] = category
|
|
128
|
+
return p
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def cache_key(url: str, params: Mapping[str, str]) -> str:
|
|
132
|
+
return url + "?" + "&".join(f"{k}={params[k]}" for k in sorted(params)) # the API key is never part of it
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def check(response: httpx.Response) -> Any:
|
|
136
|
+
"""The JSON body of a good answer; else the matching error (Pixabay answers errors in plain text)."""
|
|
137
|
+
if response.status_code == 200:
|
|
138
|
+
try:
|
|
139
|
+
return response.json()
|
|
140
|
+
except json.JSONDecodeError as e:
|
|
141
|
+
raise ServiceError("Pixabay sent an answer that is not JSON.") from e
|
|
142
|
+
text = response.text.strip()[:200]
|
|
143
|
+
if response.status_code == 429:
|
|
144
|
+
raise RateLimited("Pixabay rate limit exceeded.", retry_after=reset_seconds(response))
|
|
145
|
+
if response.status_code >= 500:
|
|
146
|
+
raise ServiceError(f"Pixabay error {response.status_code}.")
|
|
147
|
+
low = text.lower()
|
|
148
|
+
if "api key" in low:
|
|
149
|
+
raise AuthError("Invalid or missing Pixabay API key.")
|
|
150
|
+
# Live 2026-11-09: "[ERROR 400] Image #N does not exist." (older answers said "out of valid range").
|
|
151
|
+
if "does not exist" in low or "out of valid range" in low:
|
|
152
|
+
raise NotFound("Pixabay has no item with that id.")
|
|
153
|
+
raise PixabayError(f"Pixabay error {response.status_code}: {_scrub(text)}")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _scrub(text: str) -> str:
|
|
157
|
+
return re.sub(r"key=[^&\s]+", "key=***", text)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def reset_seconds(response: httpx.Response) -> float:
|
|
161
|
+
try:
|
|
162
|
+
return max(0.0, float(response.headers.get("X-RateLimit-Reset", "60")))
|
|
163
|
+
except ValueError:
|
|
164
|
+
return 60.0
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def read_rate_limit(response: httpx.Response, now: float) -> RateLimit | None:
|
|
168
|
+
h = response.headers
|
|
169
|
+
if "X-RateLimit-Remaining" not in h:
|
|
170
|
+
return None
|
|
171
|
+
try:
|
|
172
|
+
return RateLimit(int(h.get("X-RateLimit-Limit", "0")), int(h["X-RateLimit-Remaining"]),
|
|
173
|
+
now + reset_seconds(response))
|
|
174
|
+
except ValueError:
|
|
175
|
+
return None
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _parse(make: Callable[[dict[str, Any]], Any], raw: Any) -> list[Any]:
|
|
179
|
+
"""Each hit that reads cleanly; one malformed hit is skipped, not fatal to the whole answer."""
|
|
180
|
+
out = []
|
|
181
|
+
for h in raw if isinstance(raw, list) else []:
|
|
182
|
+
try:
|
|
183
|
+
out.append(make(h))
|
|
184
|
+
except (KeyError, TypeError, ValueError, AttributeError):
|
|
185
|
+
continue
|
|
186
|
+
return out
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def images_result(data: dict[str, Any], page: int, per_page: int, exclude_people: bool) -> SearchResult[Image]:
|
|
190
|
+
hits: list[Image] = _parse(Image.from_api, data.get("hits"))
|
|
191
|
+
if exclude_people:
|
|
192
|
+
hits = [h for h in hits if not PEOPLE_TAGS.intersection(t.lower() for t in h.tags)]
|
|
193
|
+
return SearchResult(int(data.get("total", 0)), int(data.get("totalHits", 0)), hits, page, per_page)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def videos_result(data: dict[str, Any], page: int, per_page: int) -> SearchResult[Video]:
|
|
197
|
+
return SearchResult(int(data.get("total", 0)), int(data.get("totalHits", 0)),
|
|
198
|
+
_parse(Video.from_api, data.get("hits")), page, per_page)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
MAX_DOWNLOAD_REDIRECTS = 5
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def check_download_url(url: str | httpx.URL) -> httpx.URL:
|
|
205
|
+
"""The URL, if it is https on one of Pixabay's own hosts; else ValueError. Checked before every hop."""
|
|
206
|
+
u = httpx.URL(str(url)) if url else httpx.URL("")
|
|
207
|
+
if u.scheme != "https" or u.host not in DOWNLOAD_HOSTS:
|
|
208
|
+
raise ValueError("Downloads come only from Pixabay's own hosts over https.")
|
|
209
|
+
return u
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def download_url(item: Image, size: Size) -> str:
|
|
213
|
+
url = {"large": item.large, "webformat": item.webformat, "preview": item.preview}[size].url
|
|
214
|
+
return str(check_download_url(url))
|
pixabay_client/client.py
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""The sync and async clients. Same methods, same rules; the async one awaits."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Iterator
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
from . import _core
|
|
13
|
+
from ._core import API, DAY, VIDEO_API, Cache, MemoryCache, Size
|
|
14
|
+
from .errors import NotFound, RateLimited, ServiceError
|
|
15
|
+
from .models import Image, RateLimit, SearchResult, Video
|
|
16
|
+
|
|
17
|
+
_UNSET: Any = object()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _Base:
|
|
21
|
+
def __init__(self, key: str | None, cache: Cache | None, cache_ttl: float, retries: int, max_wait: float,
|
|
22
|
+
clock: Callable[[], float]) -> None:
|
|
23
|
+
self._key = _core.resolve_key(key)
|
|
24
|
+
self._cache: Cache | None = MemoryCache() if cache is _UNSET else cache
|
|
25
|
+
self._ttl = cache_ttl
|
|
26
|
+
self._retries = retries
|
|
27
|
+
self._max_wait = max_wait
|
|
28
|
+
self._clock = clock
|
|
29
|
+
self.rate_limit: RateLimit | None = None
|
|
30
|
+
_core.install_log_redaction()
|
|
31
|
+
|
|
32
|
+
def __repr__(self) -> str:
|
|
33
|
+
return f"{type(self).__name__}(key=***)"
|
|
34
|
+
|
|
35
|
+
def _wait_before(self) -> float:
|
|
36
|
+
"""Seconds to wait before the next call: the window is used up and has not reset yet."""
|
|
37
|
+
rl = self.rate_limit
|
|
38
|
+
if rl is None or rl.remaining > 0:
|
|
39
|
+
return 0.0
|
|
40
|
+
return max(0.0, rl.reset_at - self._clock())
|
|
41
|
+
|
|
42
|
+
def _too_long(self, wait: float) -> None:
|
|
43
|
+
if wait > self._max_wait:
|
|
44
|
+
raise RateLimited(f"Pixabay rate limit: the wait ({wait:.0f} s) is longer than max_wait.", wait)
|
|
45
|
+
|
|
46
|
+
def _cached(self, url: str, params: dict[str, str]) -> tuple[str, Any | None]:
|
|
47
|
+
key = _core.cache_key(url, params)
|
|
48
|
+
return key, (self._cache.get(key) if self._cache is not None else None)
|
|
49
|
+
|
|
50
|
+
def _store(self, key: str, data: Any) -> None:
|
|
51
|
+
if self._cache is not None:
|
|
52
|
+
self._cache.set(key, data, self._ttl)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class PixabayClient(_Base):
|
|
56
|
+
"""Pixabay API client. `key` defaults to the PIXABAY_API_KEY environment variable."""
|
|
57
|
+
|
|
58
|
+
def __init__(self, key: str | None = None, *, cache: Cache | None = _UNSET, cache_ttl: float = DAY,
|
|
59
|
+
retries: int = 2, max_wait: float = 60.0, timeout: float = 20.0,
|
|
60
|
+
transport: httpx.BaseTransport | None = None, sleep: Callable[[float], None] = time.sleep,
|
|
61
|
+
clock: Callable[[], float] = time.monotonic) -> None:
|
|
62
|
+
super().__init__(key, cache, cache_ttl, retries, max_wait, clock)
|
|
63
|
+
self._http = httpx.Client(timeout=timeout, transport=transport, follow_redirects=True)
|
|
64
|
+
self._sleep = sleep
|
|
65
|
+
|
|
66
|
+
def __enter__(self) -> PixabayClient:
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
def __exit__(self, *exc: object) -> None:
|
|
70
|
+
self.close()
|
|
71
|
+
|
|
72
|
+
def close(self) -> None:
|
|
73
|
+
self._http.close()
|
|
74
|
+
|
|
75
|
+
def _get(self, url: str, params: dict[str, str]) -> Any:
|
|
76
|
+
key, hit = self._cached(url, params)
|
|
77
|
+
if hit is not None:
|
|
78
|
+
return hit
|
|
79
|
+
for attempt in range(self._retries + 1):
|
|
80
|
+
wait = self._wait_before()
|
|
81
|
+
if wait:
|
|
82
|
+
self._too_long(wait)
|
|
83
|
+
self._sleep(wait)
|
|
84
|
+
try:
|
|
85
|
+
response = self._http.get(url, params={**params, "key": self._key})
|
|
86
|
+
except httpx.HTTPError as e:
|
|
87
|
+
raise ServiceError(f"Pixabay could not be reached ({type(e).__name__}).") from None
|
|
88
|
+
self.rate_limit = _core.read_rate_limit(response, self._clock()) or self.rate_limit
|
|
89
|
+
try:
|
|
90
|
+
data = _core.check(response)
|
|
91
|
+
except RateLimited as e:
|
|
92
|
+
if attempt == self._retries:
|
|
93
|
+
raise
|
|
94
|
+
self._too_long(e.retry_after)
|
|
95
|
+
self._sleep(e.retry_after)
|
|
96
|
+
continue
|
|
97
|
+
self._store(key, data)
|
|
98
|
+
return data
|
|
99
|
+
raise AssertionError("unreachable")
|
|
100
|
+
|
|
101
|
+
def search_images(self, q: str | None = None, *, lang: str = "en", image_type: str = "all",
|
|
102
|
+
orientation: str = "all", category: str | None = None, min_width: int = 0, min_height: int = 0,
|
|
103
|
+
colors: Iterable[str] | None = None, editors_choice: bool = False, safesearch: bool = True,
|
|
104
|
+
order: str = "popular", page: int = 1, per_page: int = 20,
|
|
105
|
+
exclude_people: bool = False) -> SearchResult[Image]:
|
|
106
|
+
params = _core.image_params(q, lang=lang, image_type=image_type, orientation=orientation, category=category,
|
|
107
|
+
min_width=min_width, min_height=min_height, colors=colors,
|
|
108
|
+
editors_choice=editors_choice, safesearch=safesearch, order=order, page=page,
|
|
109
|
+
per_page=per_page)
|
|
110
|
+
return _core.images_result(self._get(API, params), page, per_page, exclude_people)
|
|
111
|
+
|
|
112
|
+
def iter_images(self, q: str | None = None, *, max_results: int = 100, per_page: int = 50,
|
|
113
|
+
**kwargs: Any) -> Iterator[Image]:
|
|
114
|
+
"""Every hit, page after page, up to max_results (and Pixabay's own cap)."""
|
|
115
|
+
seen, page = 0, 1
|
|
116
|
+
while seen < max_results:
|
|
117
|
+
res = self.search_images(q, page=page, per_page=per_page, **kwargs)
|
|
118
|
+
for hit in res.hits:
|
|
119
|
+
if seen == max_results:
|
|
120
|
+
return
|
|
121
|
+
seen += 1
|
|
122
|
+
yield hit
|
|
123
|
+
if not res.hits or page * per_page >= res.total_hits:
|
|
124
|
+
return
|
|
125
|
+
page += 1
|
|
126
|
+
|
|
127
|
+
def get_image(self, image_id: int) -> Image:
|
|
128
|
+
data = self._get(API, {"id": str(image_id)})
|
|
129
|
+
hits = _core.images_result(data, 1, 1, False).hits
|
|
130
|
+
return hits[0] if hits else _not_found()
|
|
131
|
+
|
|
132
|
+
def search_videos(self, q: str | None = None, *, lang: str = "en", video_type: str = "all",
|
|
133
|
+
category: str | None = None, min_width: int = 0, min_height: int = 0,
|
|
134
|
+
editors_choice: bool = False, safesearch: bool = True, order: str = "popular", page: int = 1,
|
|
135
|
+
per_page: int = 20) -> SearchResult[Video]:
|
|
136
|
+
params = _core.video_params(q, lang=lang, video_type=video_type, category=category, min_width=min_width,
|
|
137
|
+
min_height=min_height, editors_choice=editors_choice, safesearch=safesearch,
|
|
138
|
+
order=order, page=page, per_page=per_page)
|
|
139
|
+
return _core.videos_result(self._get(VIDEO_API, params), page, per_page)
|
|
140
|
+
|
|
141
|
+
def get_video(self, video_id: int) -> Video:
|
|
142
|
+
data = self._get(VIDEO_API, {"id": str(video_id)})
|
|
143
|
+
hits = _core.videos_result(data, 1, 1).hits
|
|
144
|
+
return hits[0] if hits else _not_found()
|
|
145
|
+
|
|
146
|
+
def download(self, image: Image, *, size: Size = "large", dest: str | Path | None = None) -> Any:
|
|
147
|
+
"""The picture's bytes, or with `dest` saved there (returns the Path). Pixabay forbids permanent
|
|
148
|
+
hotlinking: download what you keep."""
|
|
149
|
+
url = httpx.URL(_core.download_url(image, size))
|
|
150
|
+
try:
|
|
151
|
+
for _ in range(_core.MAX_DOWNLOAD_REDIRECTS + 1):
|
|
152
|
+
response = self._http.get(url, follow_redirects=False)
|
|
153
|
+
if not response.is_redirect:
|
|
154
|
+
break
|
|
155
|
+
url = _core.check_download_url(response.next_request.url if response.next_request else "")
|
|
156
|
+
else:
|
|
157
|
+
raise ServiceError("The download redirected too many times.")
|
|
158
|
+
response.raise_for_status()
|
|
159
|
+
except httpx.HTTPError as e:
|
|
160
|
+
raise ServiceError(f"The download failed ({type(e).__name__}).") from None
|
|
161
|
+
return _save(response.content, dest)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class AsyncPixabayClient(_Base):
|
|
165
|
+
"""The async twin of PixabayClient."""
|
|
166
|
+
|
|
167
|
+
def __init__(self, key: str | None = None, *, cache: Cache | None = _UNSET, cache_ttl: float = DAY,
|
|
168
|
+
retries: int = 2, max_wait: float = 60.0, timeout: float = 20.0,
|
|
169
|
+
transport: httpx.AsyncBaseTransport | None = None,
|
|
170
|
+
sleep: Callable[[float], Awaitable[None]] = asyncio.sleep,
|
|
171
|
+
clock: Callable[[], float] = time.monotonic) -> None:
|
|
172
|
+
super().__init__(key, cache, cache_ttl, retries, max_wait, clock)
|
|
173
|
+
self._http = httpx.AsyncClient(timeout=timeout, transport=transport, follow_redirects=True)
|
|
174
|
+
self._sleep = sleep
|
|
175
|
+
|
|
176
|
+
async def __aenter__(self) -> AsyncPixabayClient:
|
|
177
|
+
return self
|
|
178
|
+
|
|
179
|
+
async def __aexit__(self, *exc: object) -> None:
|
|
180
|
+
await self.close()
|
|
181
|
+
|
|
182
|
+
async def close(self) -> None:
|
|
183
|
+
await self._http.aclose()
|
|
184
|
+
|
|
185
|
+
async def _get(self, url: str, params: dict[str, str]) -> Any:
|
|
186
|
+
key, hit = self._cached(url, params)
|
|
187
|
+
if hit is not None:
|
|
188
|
+
return hit
|
|
189
|
+
for attempt in range(self._retries + 1):
|
|
190
|
+
wait = self._wait_before()
|
|
191
|
+
if wait:
|
|
192
|
+
self._too_long(wait)
|
|
193
|
+
await self._sleep(wait)
|
|
194
|
+
try:
|
|
195
|
+
response = await self._http.get(url, params={**params, "key": self._key})
|
|
196
|
+
except httpx.HTTPError as e:
|
|
197
|
+
raise ServiceError(f"Pixabay could not be reached ({type(e).__name__}).") from None
|
|
198
|
+
self.rate_limit = _core.read_rate_limit(response, self._clock()) or self.rate_limit
|
|
199
|
+
try:
|
|
200
|
+
data = _core.check(response)
|
|
201
|
+
except RateLimited as e:
|
|
202
|
+
if attempt == self._retries:
|
|
203
|
+
raise
|
|
204
|
+
self._too_long(e.retry_after)
|
|
205
|
+
await self._sleep(e.retry_after)
|
|
206
|
+
continue
|
|
207
|
+
self._store(key, data)
|
|
208
|
+
return data
|
|
209
|
+
raise AssertionError("unreachable")
|
|
210
|
+
|
|
211
|
+
async def search_images(self, q: str | None = None, *, lang: str = "en", image_type: str = "all",
|
|
212
|
+
orientation: str = "all", category: str | None = None, min_width: int = 0,
|
|
213
|
+
min_height: int = 0, colors: Iterable[str] | None = None, editors_choice: bool = False,
|
|
214
|
+
safesearch: bool = True, order: str = "popular", page: int = 1, per_page: int = 20,
|
|
215
|
+
exclude_people: bool = False) -> SearchResult[Image]:
|
|
216
|
+
params = _core.image_params(q, lang=lang, image_type=image_type, orientation=orientation, category=category,
|
|
217
|
+
min_width=min_width, min_height=min_height, colors=colors,
|
|
218
|
+
editors_choice=editors_choice, safesearch=safesearch, order=order, page=page,
|
|
219
|
+
per_page=per_page)
|
|
220
|
+
return _core.images_result(await self._get(API, params), page, per_page, exclude_people)
|
|
221
|
+
|
|
222
|
+
async def iter_images(self, q: str | None = None, *, max_results: int = 100, per_page: int = 50,
|
|
223
|
+
**kwargs: Any) -> AsyncIterator[Image]:
|
|
224
|
+
seen, page = 0, 1
|
|
225
|
+
while seen < max_results:
|
|
226
|
+
res = await self.search_images(q, page=page, per_page=per_page, **kwargs)
|
|
227
|
+
for hit in res.hits:
|
|
228
|
+
if seen == max_results:
|
|
229
|
+
return
|
|
230
|
+
seen += 1
|
|
231
|
+
yield hit
|
|
232
|
+
if not res.hits or page * per_page >= res.total_hits:
|
|
233
|
+
return
|
|
234
|
+
page += 1
|
|
235
|
+
|
|
236
|
+
async def get_image(self, image_id: int) -> Image:
|
|
237
|
+
data = await self._get(API, {"id": str(image_id)})
|
|
238
|
+
hits = _core.images_result(data, 1, 1, False).hits
|
|
239
|
+
return hits[0] if hits else _not_found()
|
|
240
|
+
|
|
241
|
+
async def search_videos(self, q: str | None = None, *, lang: str = "en", video_type: str = "all",
|
|
242
|
+
category: str | None = None, min_width: int = 0, min_height: int = 0,
|
|
243
|
+
editors_choice: bool = False, safesearch: bool = True, order: str = "popular",
|
|
244
|
+
page: int = 1, per_page: int = 20) -> SearchResult[Video]:
|
|
245
|
+
params = _core.video_params(q, lang=lang, video_type=video_type, category=category, min_width=min_width,
|
|
246
|
+
min_height=min_height, editors_choice=editors_choice, safesearch=safesearch,
|
|
247
|
+
order=order, page=page, per_page=per_page)
|
|
248
|
+
return _core.videos_result(await self._get(VIDEO_API, params), page, per_page)
|
|
249
|
+
|
|
250
|
+
async def get_video(self, video_id: int) -> Video:
|
|
251
|
+
data = await self._get(VIDEO_API, {"id": str(video_id)})
|
|
252
|
+
hits = _core.videos_result(data, 1, 1).hits
|
|
253
|
+
return hits[0] if hits else _not_found()
|
|
254
|
+
|
|
255
|
+
async def download(self, image: Image, *, size: Size = "large", dest: str | Path | None = None) -> Any:
|
|
256
|
+
url = httpx.URL(_core.download_url(image, size))
|
|
257
|
+
try:
|
|
258
|
+
for _ in range(_core.MAX_DOWNLOAD_REDIRECTS + 1):
|
|
259
|
+
response = await self._http.get(url, follow_redirects=False)
|
|
260
|
+
if not response.is_redirect:
|
|
261
|
+
break
|
|
262
|
+
url = _core.check_download_url(response.next_request.url if response.next_request else "")
|
|
263
|
+
else:
|
|
264
|
+
raise ServiceError("The download redirected too many times.")
|
|
265
|
+
response.raise_for_status()
|
|
266
|
+
except httpx.HTTPError as e:
|
|
267
|
+
raise ServiceError(f"The download failed ({type(e).__name__}).") from None
|
|
268
|
+
return _save(response.content, dest)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _not_found() -> Any:
|
|
272
|
+
raise NotFound("Pixabay has no item with that id.")
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _save(content: bytes, dest: str | Path | None) -> bytes | Path:
|
|
276
|
+
if dest is None:
|
|
277
|
+
return content
|
|
278
|
+
path = Path(dest)
|
|
279
|
+
path.write_bytes(content)
|
|
280
|
+
return path
|
pixabay_client/errors.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Errors. Messages never contain the API key."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PixabayError(Exception):
|
|
6
|
+
"""Base class for every error this client raises."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AuthError(PixabayError):
|
|
10
|
+
"""The API key is missing or invalid."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NotFound(PixabayError):
|
|
14
|
+
"""No image or video with that id."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RateLimited(PixabayError):
|
|
18
|
+
"""Still rate limited after the retries (or the wait would exceed max_wait)."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, message: str, retry_after: float = 60.0) -> None:
|
|
21
|
+
super().__init__(message)
|
|
22
|
+
self.retry_after = retry_after
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ServiceError(PixabayError):
|
|
26
|
+
"""Pixabay answered 5xx, sent something unreadable, or could not be reached."""
|
pixabay_client/models.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Typed Pixabay results."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from html import escape
|
|
6
|
+
from typing import Any, Generic, TypeVar
|
|
7
|
+
from urllib.parse import quote
|
|
8
|
+
|
|
9
|
+
T = TypeVar("T")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _tags(raw: str) -> tuple[str, ...]:
|
|
13
|
+
return tuple(t.strip() for t in raw.split(",") if t.strip())
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _user_url(user: str, user_id: int) -> str:
|
|
17
|
+
return f"https://pixabay.com/users/{quote(user)}-{user_id}/"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Rendition:
|
|
22
|
+
url: str
|
|
23
|
+
width: int
|
|
24
|
+
height: int
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class VideoRendition(Rendition):
|
|
29
|
+
size: int
|
|
30
|
+
thumbnail: str
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class _Hit:
|
|
35
|
+
id: int
|
|
36
|
+
page_url: str
|
|
37
|
+
type: str
|
|
38
|
+
tags: tuple[str, ...]
|
|
39
|
+
views: int
|
|
40
|
+
downloads: int
|
|
41
|
+
likes: int
|
|
42
|
+
comments: int
|
|
43
|
+
user: str
|
|
44
|
+
user_id: int
|
|
45
|
+
user_image_url: str
|
|
46
|
+
|
|
47
|
+
_noun = "Image"
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def user_url(self) -> str:
|
|
51
|
+
return _user_url(self.user, self.user_id)
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def credit(self) -> str:
|
|
55
|
+
"""The plain "where it's from" line Pixabay asks you to show."""
|
|
56
|
+
return f"{self._noun} by {self.user} from Pixabay"
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def credit_html(self) -> str:
|
|
60
|
+
"""The credit as HTML links (to the author and to the picture's Pixabay page), safely escaped."""
|
|
61
|
+
return (f'{self._noun} by <a href="{escape(self.user_url)}">{escape(self.user)}</a> from '
|
|
62
|
+
f'<a href="{escape(self.page_url)}">Pixabay</a>')
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _common(d: dict[str, Any]) -> dict[str, Any]:
|
|
66
|
+
return {
|
|
67
|
+
"id": int(d["id"]), "page_url": d.get("pageURL", ""), "type": d.get("type", ""),
|
|
68
|
+
"tags": _tags(d.get("tags", "")), "views": int(d.get("views", 0)), "downloads": int(d.get("downloads", 0)),
|
|
69
|
+
"likes": int(d.get("likes", 0)), "comments": int(d.get("comments", 0)), "user": d.get("user", ""),
|
|
70
|
+
"user_id": int(d.get("user_id", 0)), "user_image_url": d.get("userImageURL", ""),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass(frozen=True)
|
|
75
|
+
class Image(_Hit):
|
|
76
|
+
preview: Rendition = field(default_factory=lambda: Rendition("", 0, 0))
|
|
77
|
+
webformat: Rendition = field(default_factory=lambda: Rendition("", 0, 0)) # max 640 px; URL valid 24 hours
|
|
78
|
+
large: Rendition = field(default_factory=lambda: Rendition("", 0, 0)) # max 1280 px
|
|
79
|
+
width: int = 0 # the original's size
|
|
80
|
+
height: int = 0
|
|
81
|
+
size: int = 0
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def from_api(cls, d: dict[str, Any]) -> Image:
|
|
85
|
+
w, h = int(d.get("imageWidth", 0)), int(d.get("imageHeight", 0))
|
|
86
|
+
# Pixabay gives no size for the large rendition: the original scaled to at most 1280 px.
|
|
87
|
+
scale = min(1.0, 1280 / max(w, h, 1))
|
|
88
|
+
return cls(
|
|
89
|
+
**_common(d),
|
|
90
|
+
preview=Rendition(d.get("previewURL", ""), int(d.get("previewWidth", 0)), int(d.get("previewHeight", 0))),
|
|
91
|
+
webformat=Rendition(d.get("webformatURL", ""), int(d.get("webformatWidth", 0)),
|
|
92
|
+
int(d.get("webformatHeight", 0))),
|
|
93
|
+
large=Rendition(d.get("largeImageURL", ""), round(w * scale), round(h * scale)),
|
|
94
|
+
width=w, height=h, size=int(d.get("imageSize", 0)),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True)
|
|
99
|
+
class Video(_Hit):
|
|
100
|
+
duration: int = 0
|
|
101
|
+
renditions: dict[str, VideoRendition] = field(default_factory=dict) # large, medium, small, tiny (if present)
|
|
102
|
+
|
|
103
|
+
_noun = "Video"
|
|
104
|
+
|
|
105
|
+
@classmethod
|
|
106
|
+
def from_api(cls, d: dict[str, Any]) -> Video:
|
|
107
|
+
renditions = {
|
|
108
|
+
name: VideoRendition(r.get("url", ""), int(r.get("width", 0)), int(r.get("height", 0)),
|
|
109
|
+
int(r.get("size", 0)), r.get("thumbnail", ""))
|
|
110
|
+
for name, r in (d.get("videos") or {}).items() if r.get("url")
|
|
111
|
+
}
|
|
112
|
+
return cls(**_common(d), duration=int(d.get("duration", 0)), renditions=renditions)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@dataclass(frozen=True)
|
|
116
|
+
class SearchResult(Generic[T]):
|
|
117
|
+
total: int # all matches on Pixabay
|
|
118
|
+
total_hits: int # matches reachable through the API (Pixabay caps this, usually at 500)
|
|
119
|
+
hits: list[T]
|
|
120
|
+
page: int
|
|
121
|
+
per_page: int
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@dataclass(frozen=True)
|
|
125
|
+
class RateLimit:
|
|
126
|
+
limit: int
|
|
127
|
+
remaining: int
|
|
128
|
+
reset_at: float # clock time when the window resets
|
pixabay_client/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pixabay-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A typed Pixabay API client (sync and async) that follows Pixabay's API rules for you: caching, rate limits, downloads and credit.
|
|
5
|
+
Project-URL: Homepage, https://github.com/grasshopperpebbles-oss/pixabay-client
|
|
6
|
+
Project-URL: Source, https://github.com/grasshopperpebbles-oss/pixabay-client
|
|
7
|
+
Project-URL: Issues, https://github.com/grasshopperpebbles-oss/pixabay-client/issues
|
|
8
|
+
Author: Les Green
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,async,client,images,pixabay,stock photos
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: httpx<1,>=0.27
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# pixabay-client
|
|
30
|
+
|
|
31
|
+
A typed Python client for the [Pixabay API](https://pixabay.com/api/docs/), sync and async, that **follows
|
|
32
|
+
Pixabay's API rules for you**:
|
|
33
|
+
|
|
34
|
+
- **Caching:** Pixabay asks that requests be cached for 24 hours. Results are cached in memory for 24 hours by
|
|
35
|
+
default (bring your own cache, or turn it off).
|
|
36
|
+
- **Rate limits:** reads `X-RateLimit-*` headers, waits when the window is used up, and retries a `429` after the
|
|
37
|
+
reset time.
|
|
38
|
+
- **No hotlinking:** Pixabay forbids permanent hotlinking. `download()` saves the picture for you, and only ever
|
|
39
|
+
fetches from Pixabay's own hosts, including after redirects.
|
|
40
|
+
- **Credit:** `image.credit` / `image.credit_html` give the "where it's from" line Pixabay asks you to show.
|
|
41
|
+
- **Your key stays private:** never in `repr`, error messages or logs (httpx's request log line is redacted).
|
|
42
|
+
- **Safe by default:** `safesearch` is on unless you turn it off; optional `exclude_people=True` drops hits
|
|
43
|
+
tagged with people.
|
|
44
|
+
- Images **and** videos, typed results (`py.typed`), Python 3.10+, one dependency (`httpx`).
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install pixabay-client
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Use
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from pixabay_client import PixabayClient
|
|
54
|
+
|
|
55
|
+
with PixabayClient("YOUR_KEY") as px: # or set PIXABAY_API_KEY
|
|
56
|
+
result = px.search_images("tabby cat", image_type="photo", per_page=20)
|
|
57
|
+
for img in result.hits:
|
|
58
|
+
print(img.id, img.tags, img.webformat.url, img.credit)
|
|
59
|
+
|
|
60
|
+
img = px.get_image(result.hits[0].id)
|
|
61
|
+
px.download(img, dest="cat.jpg") # size: "large" (default), "webformat" or "preview"
|
|
62
|
+
|
|
63
|
+
for img in px.iter_images("fox", max_results=100): # pages for you
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
videos = px.search_videos("waves", video_type="film")
|
|
67
|
+
clip = videos.hits[0].renditions["medium"] # large / medium / small / tiny (missing ones left out)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Async:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from pixabay_client import AsyncPixabayClient
|
|
74
|
+
|
|
75
|
+
async with AsyncPixabayClient() as px:
|
|
76
|
+
result = await px.search_images("owl")
|
|
77
|
+
data = await px.download(result.hits[0])
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Errors
|
|
81
|
+
|
|
82
|
+
| Exception | When |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `AuthError` | missing or invalid API key |
|
|
85
|
+
| `NotFound` | `get_image` / `get_video` with an id Pixabay does not have |
|
|
86
|
+
| `RateLimited` | still rate limited after the retries (`retries=2` by default) |
|
|
87
|
+
| `ServiceError` | Pixabay answered 5xx or could not be reached |
|
|
88
|
+
| `PixabayError` | base class; any other error |
|
|
89
|
+
|
|
90
|
+
### Options
|
|
91
|
+
|
|
92
|
+
`PixabayClient(key=None, *, cache=MemoryCache(), cache_ttl=86400, retries=2, max_wait=60, timeout=20,
|
|
93
|
+
transport=None)`. `cache=None` turns caching off; any object with `get(key)` / `set(key, value, ttl)` works as a
|
|
94
|
+
cache (Redis, disk…). Waits longer than `max_wait` seconds raise `RateLimited` instead of sleeping.
|
|
95
|
+
|
|
96
|
+
## Pixabay's terms
|
|
97
|
+
|
|
98
|
+
You need a free API key from [pixabay.com/api/docs](https://pixabay.com/api/docs/). The API is for real human
|
|
99
|
+
requests: no systematic mass downloads. Show your users where pictures come from. Read the
|
|
100
|
+
[Pixabay content license](https://pixabay.com/service/license-summary/): depicted people, trademarks and
|
|
101
|
+
privacy rights can still apply to a picture.
|
|
102
|
+
|
|
103
|
+
Not affiliated with Pixabay.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pixabay_client/__init__.py,sha256=QXI8yvBvehgDbT4Ksljq723tCmR5Xuki80SKuepjFLg,607
|
|
2
|
+
pixabay_client/_core.py,sha256=usFN89ry-W18khYf0Xb47RdL824QPPjQWsWybcTtef4,8488
|
|
3
|
+
pixabay_client/client.py,sha256=N_7pfXxRVXZ9C5wOZrK-WMVQg9KHtIkgUa0UGPfh1zs,13440
|
|
4
|
+
pixabay_client/errors.py,sha256=WD7GmTuQvRkO825r284hIQdtjL80p1HPxRjO2ycoiiM,713
|
|
5
|
+
pixabay_client/models.py,sha256=ZpDmRZsxmGHEbDqlLatyXNbDl6LmEsBC8m8n_hk-l28,4154
|
|
6
|
+
pixabay_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
pixabay_client-0.1.0.dist-info/METADATA,sha256=txwt2JA1S0EZMOOaXkzTCKd1iA7BWR_Hq-zanljFWOI,4323
|
|
8
|
+
pixabay_client-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
9
|
+
pixabay_client-0.1.0.dist-info/licenses/LICENSE,sha256=4_Yq3GqTb96Ny7qCh7PhwBSLqyEV5tQrEIBuU9M3jsM,1066
|
|
10
|
+
pixabay_client-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Les Green
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|