hyperion-sdk 0.2.0.dev1741815359__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.
- hyperion/__init__.py +0 -0
- hyperion/asyncutils.py +79 -0
- hyperion/catalog/__init__.py +8 -0
- hyperion/catalog/catalog.py +623 -0
- hyperion/catalog/schema.py +153 -0
- hyperion/collections/__init__.py +0 -0
- hyperion/collections/asset_collection.py +285 -0
- hyperion/config.py +77 -0
- hyperion/dateutils.py +238 -0
- hyperion/entities/__init__.py +0 -0
- hyperion/entities/catalog.py +190 -0
- hyperion/infrastructure/__init__.py +0 -0
- hyperion/infrastructure/aws.py +220 -0
- hyperion/infrastructure/cache.py +396 -0
- hyperion/infrastructure/geo/__init__.py +7 -0
- hyperion/infrastructure/geo/gmaps.py +124 -0
- hyperion/infrastructure/geo/location.py +186 -0
- hyperion/infrastructure/http.py +62 -0
- hyperion/infrastructure/keyval.py +264 -0
- hyperion/infrastructure/queue.py +151 -0
- hyperion/infrastructure/secrets.py +63 -0
- hyperion/logging.py +122 -0
- hyperion/py.typed +0 -0
- hyperion/sources/__init__.py +0 -0
- hyperion/sources/base.py +105 -0
- hyperion/typeutils.py +52 -0
- hyperion_sdk-0.2.0.dev1741815359.dist-info/METADATA +476 -0
- hyperion_sdk-0.2.0.dev1741815359.dist-info/RECORD +29 -0
- hyperion_sdk-0.2.0.dev1741815359.dist-info/WHEEL +4 -0
hyperion/__init__.py
ADDED
|
File without changes
|
hyperion/asyncutils.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import inspect
|
|
3
|
+
import sys
|
|
4
|
+
from collections.abc import AsyncIterable, AsyncIterator, Callable, Coroutine, Iterable
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Generic, TypeVar
|
|
6
|
+
|
|
7
|
+
from hyperion.logging import get_logger
|
|
8
|
+
|
|
9
|
+
if sys.version_info >= (3, 11) and TYPE_CHECKING:
|
|
10
|
+
from typing import Self
|
|
11
|
+
|
|
12
|
+
if sys.version_info < (3, 11) and TYPE_CHECKING:
|
|
13
|
+
from typing_extensions import Self
|
|
14
|
+
|
|
15
|
+
T = TypeVar("T")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
logger = get_logger("hyperion-asyncutils")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def iter_async(iterable: Iterable[T]) -> AsyncIterator[T]:
|
|
22
|
+
for item in iterable:
|
|
23
|
+
yield item
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async def aiter_any(
|
|
27
|
+
iterable: Iterable[T] | AsyncIterable[T] | Callable[[], Iterable[T] | AsyncIterable[T]],
|
|
28
|
+
) -> AsyncIterator[T]:
|
|
29
|
+
asyncgen: AsyncIterable[T]
|
|
30
|
+
if inspect.isasyncgen(iterable) or isinstance(iterable, AsyncIterable):
|
|
31
|
+
asyncgen = iterable
|
|
32
|
+
elif inspect.isasyncgenfunction(iterable):
|
|
33
|
+
asyncgen = iterable()
|
|
34
|
+
elif inspect.isgenerator(iterable) or isinstance(iterable, Iterable):
|
|
35
|
+
asyncgen = iter_async(iterable)
|
|
36
|
+
elif inspect.isgeneratorfunction(iterable):
|
|
37
|
+
asyncgen = iter_async(iterable())
|
|
38
|
+
else:
|
|
39
|
+
raise TypeError("Provided value cannot be iterated over.")
|
|
40
|
+
async for item in asyncgen:
|
|
41
|
+
yield item
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_loop() -> asyncio.AbstractEventLoop:
|
|
45
|
+
"""Get the current running loop or create a new one if not running."""
|
|
46
|
+
try:
|
|
47
|
+
return asyncio.get_running_loop()
|
|
48
|
+
except RuntimeError:
|
|
49
|
+
loop = asyncio.new_event_loop()
|
|
50
|
+
asyncio.set_event_loop(loop)
|
|
51
|
+
return loop
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class AsyncTaskQueue(Generic[T]):
|
|
55
|
+
def __init__(self, maxsize: int = 0) -> None:
|
|
56
|
+
self.tasklist: list[asyncio.Task[T]] = []
|
|
57
|
+
self._entered = False
|
|
58
|
+
self.maxsize = maxsize
|
|
59
|
+
|
|
60
|
+
async def _flush(self) -> None:
|
|
61
|
+
logger.debug(f"Max size of {self.maxsize} reached, waiting for enqueued tasks to finish.")
|
|
62
|
+
await asyncio.gather(*self.tasklist)
|
|
63
|
+
self.tasklist = []
|
|
64
|
+
|
|
65
|
+
async def __aenter__(self) -> "Self":
|
|
66
|
+
self.tasklist = []
|
|
67
|
+
self._entered = True
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
async def __aexit__(self, *args: Any) -> None:
|
|
71
|
+
self._entered = False
|
|
72
|
+
await self._flush()
|
|
73
|
+
|
|
74
|
+
async def add_task(self, coroutine: Coroutine[Any, Any, T]) -> None:
|
|
75
|
+
if not self._entered:
|
|
76
|
+
raise RuntimeError(f"{self.__class__.__name__!r} must be used in an 'async with' context.")
|
|
77
|
+
if self.maxsize and len(self.tasklist) >= self.maxsize:
|
|
78
|
+
await self._flush()
|
|
79
|
+
self.tasklist.append(asyncio.create_task(coroutine))
|