THE ORIONIS API
Build with clarity.
Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.
class Loop: (source)
Thread-safe, platform-aware asyncio event loop manager for the Orionis Framework.
Centralises every aspect of event loop lifecycle:
- Optimal factory selection: uvloop (non-Windows) → ProactorEventLoop (Windows) → stdlib default.
- Per-thread loop creation and caching to prevent cross-thread sharing.
- Transparent bridging between synchronous and asynchronous execution contexts without deadlocking a running loop.
- Cooperative task cancellation and cleanup on context-manager exit.
All state is class-level; no instance creation is required or intended.
| Class Method | _detect |
Detect and cache the uvloop event loop factory, if available. |
| Class Method | _get |
Return the best available event loop factory for the current platform. |
| Class Method | _get |
Return the shared single-worker thread pool used for sync↔async bridging. |
| Class Method | get |
Return the event loop for the current thread, creating one if necessary. |
| Class Method | run |
Run a coroutine synchronously from any context. |
| Static Method | _get |
Return the event loop currently running in this thread, or None. |
| Async Static Method | create |
Create and schedule a new asyncio task for coro. |
| Static Method | event |
Context manager that provides an event loop and cleans up on exit. |
| Async Static Method | execute |
Transparently execute a sync or async callable. |
| Static Method | is |
Return True if an event loop is currently running in the calling thread. |
| Static Method | run |
Execute a coroutine as the application entry point. |
| Constant | _IS |
Undocumented |
| Class Variable | _loop |
Undocumented |
| Class Variable | _loop |
Undocumented |
| Class Variable | _loop |
Undocumented |
| Class Variable | _loop |
Undocumented |
| Class Variable | _sync |
Undocumented |
| Class Variable | _sync |
Undocumented |
| Class Variable | _uvloop |
Undocumented |
| Class Variable | _uvloop |
Undocumented |
Detect and cache the uvloop event loop factory, if available.
Uses double-checked locking so detection occurs at most once across all threads; subsequent calls return the cached result immediately.
| Returns | |
Callable or None | uvloop.new_event_loop when available on a non-Windows platform, otherwise None. |
Return the best available event loop factory for the current platform.
Resolution order:
- uvloop (non-Windows only).
- asyncio.ProactorEventLoop (Windows only).
- None — the caller falls back to asyncio.new_event_loop().
The result is cached after the first call; repeated invocations are essentially free.
| Returns | |
Callable or None | Undocumented |
Return the shared single-worker thread pool used for sync↔async bridging.
The pool is created lazily on first access via double-checked locking and reused for all subsequent calls, keeping thread-creation overhead off hot paths.
| Returns | |
concurrent.futures.ThreadPoolExecutor | Undocumented |
Return the event loop for the current thread, creating one if necessary.
If a loop is already running in the calling thread it is returned immediately. Otherwise the per-thread cached loop is returned; a fresh loop is created and registered when no valid cached one exists.
| Returns | |
asyncio.AbstractEventLoop | Undocumented |
Run a coroutine synchronously from any context.
When no loop is running, delegates directly to run.
When a loop is already running (e.g. inside an async framework),
the coroutine is dispatched to the shared single-worker thread pool
so it runs its own loop without deadlocking the caller.
| Parameters | |
coro:Coroutine | |
| Returns | |
Any | Undocumented |
Return the event loop currently running in this thread, or None.
Uses the public asyncio.get_running_loop() API with a try/except to avoid relying on CPython private internals. The overhead is negligible when a loop is present (fast path).
| Returns | |
asyncio.AbstractEventLoop or None | Undocumented |
Coroutine[ Any, Any, T], *, name: str | None = None) -> asyncio.Task[ T]:
(source)
¶
Create and schedule a new asyncio task for coro.
| Parameters | |
coro:Coroutine | The coroutine to schedule. |
name:str or None, optional | An optional descriptive name for the task. |
| Returns | |
asyncio.Task | Undocumented |
@contextmanager
Generator[ asyncio.AbstractEventLoop]:
(source)
¶
Context manager that provides an event loop and cleans up on exit.
Pending tasks are cancelled cooperatively and awaited with return_exceptions=True so no exception escapes the finally block.
| Yields | |
asyncio.AbstractEventLoop | Undocumented |
Transparently execute a sync or async callable.
Async callables are awaited directly; synchronous callables are offloaded to the event loop's default executor to avoid blocking the loop thread.
| Parameters | |
func:Callable | The function or coroutine function to invoke. |
*args:Any | Positional arguments forwarded to func. |
**kwargs:Any | Keyword arguments forwarded to func. |
| Returns | |
Any | Undocumented |
| Raises | |
TypeError | If func is not callable. |
Execute a coroutine as the application entry point.
Designed to be called from a context with no running event loop (e.g. CLI __main__). Passes KeyboardInterrupt cleanly so the process exits with code 0 on Ctrl+C.
| Parameters | |
coro:Coroutine | The coroutine object to run. |
| Returns | |
Any | The value returned by the coroutine, or 0 on KeyboardInterrupt. |
| Raises | |
TypeError | If coro is not a coroutine object. |
RuntimeError | Raised when a loop is already running in the calling thread.
The message matches the relevant standard library
entry point (asyncio.Runner or asyncio.run); coro is left
unconsumed. Use runSync to bridge into a running loop. |