| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
|
| 5 |
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 6 |
from ..core.request_options import RequestOptions |
| 7 |
from ..types.event_stream_subscribe_events_event_type_enum import EventStreamSubscribeEventsEventTypeEnum |
| 8 |
from ..types.event_stream_subscribe_events_response_content import EventStreamSubscribeEventsResponseContent |
| 9 |
from .raw_client import AsyncRawEventsClient, RawEventsClient |
| 10 |
|
| 11 |
|
| 12 |
class EventsClient: |
| 13 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 14 |
self._raw_client = RawEventsClient(client_wrapper=client_wrapper) |
| 15 |
|
| 16 |
@property |
| 17 |
def with_raw_response(self) -> RawEventsClient: |
| 18 |
""" |
| 19 |
Retrieves a raw implementation of this client that returns raw responses. |
| 20 |
|
| 21 |
Returns |
| 22 |
------- |
| 23 |
RawEventsClient |
| 24 |
""" |
| 25 |
return self._raw_client |
| 26 |
|
| 27 |
def subscribe( |
| 28 |
self, |
| 29 |
*, |
| 30 |
from_: typing.Optional[str] = None, |
| 31 |
from_timestamp: typing.Optional[str] = None, |
| 32 |
event_type: typing.Optional[ |
| 33 |
typing.Union[ |
| 34 |
EventStreamSubscribeEventsEventTypeEnum, typing.Sequence[EventStreamSubscribeEventsEventTypeEnum] |
| 35 |
] |
| 36 |
] = None, |
| 37 |
request_options: typing.Optional[RequestOptions] = None, |
| 38 |
) -> typing.Iterator[EventStreamSubscribeEventsResponseContent]: |
| 39 |
""" |
| 40 |
Subscribe to events via Server-Sent Events (SSE) |
| 41 |
|
| 42 |
Parameters |
| 43 |
---------- |
| 44 |
from_ : typing.Optional[str] |
| 45 |
Opaque token representing position in the stream. If not provided, stream will start from the latest events. |
| 46 |
|
| 47 |
from_timestamp : typing.Optional[str] |
| 48 |
RFC-3339 timestamp indicating where to start streaming events from. This should only be used on the initial query when a cursor may not be available. Subsequent requests should use the cursor (from) as it will be more accurate. |
| 49 |
|
| 50 |
event_type : typing.Optional[typing.Union[EventStreamSubscribeEventsEventTypeEnum, typing.Sequence[EventStreamSubscribeEventsEventTypeEnum]]] |
| 51 |
Event type(s) to listen for. Specify multiple times for multiple types (e.g., ?event_type=user.created&event_type=user.updated). If not provided, all event types will be streamed. |
| 52 |
|
| 53 |
request_options : typing.Optional[RequestOptions] |
| 54 |
Request-specific configuration. |
| 55 |
|
| 56 |
Yields |
| 57 |
------ |
| 58 |
typing.Iterator[EventStreamSubscribeEventsResponseContent] |
| 59 |
Event stream successfully established. |
| 60 |
|
| 61 |
Examples |
| 62 |
-------- |
| 63 |
from auth0 import Auth0 |
| 64 |
|
| 65 |
client = Auth0( |
| 66 |
token="YOUR_TOKEN", |
| 67 |
) |
| 68 |
response = client.events.subscribe( |
| 69 |
from_="from", |
| 70 |
from_timestamp="from_timestamp", |
| 71 |
event_type=["connection.created"], |
| 72 |
) |
| 73 |
for chunk in response: |
| 74 |
yield chunk |
| 75 |
""" |
| 76 |
with self._raw_client.subscribe( |
| 77 |
from_=from_, from_timestamp=from_timestamp, event_type=event_type, request_options=request_options |
| 78 |
) as r: |
| 79 |
yield from r.data |
| 80 |
|
| 81 |
|
| 82 |
class AsyncEventsClient: |
| 83 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 84 |
self._raw_client = AsyncRawEventsClient(client_wrapper=client_wrapper) |
| 85 |
|
| 86 |
@property |
| 87 |
def with_raw_response(self) -> AsyncRawEventsClient: |
| 88 |
""" |
| 89 |
Retrieves a raw implementation of this client that returns raw responses. |
| 90 |
|
| 91 |
Returns |
| 92 |
------- |
| 93 |
AsyncRawEventsClient |
| 94 |
""" |
| 95 |
return self._raw_client |
| 96 |
|
| 97 |
async def subscribe( |
| 98 |
self, |
| 99 |
*, |
| 100 |
from_: typing.Optional[str] = None, |
| 101 |
from_timestamp: typing.Optional[str] = None, |
| 102 |
event_type: typing.Optional[ |
| 103 |
typing.Union[ |
| 104 |
EventStreamSubscribeEventsEventTypeEnum, typing.Sequence[EventStreamSubscribeEventsEventTypeEnum] |
| 105 |
] |
| 106 |
] = None, |
| 107 |
request_options: typing.Optional[RequestOptions] = None, |
| 108 |
) -> typing.AsyncIterator[EventStreamSubscribeEventsResponseContent]: |
| 109 |
""" |
| 110 |
Subscribe to events via Server-Sent Events (SSE) |
| 111 |
|
| 112 |
Parameters |
| 113 |
---------- |
| 114 |
from_ : typing.Optional[str] |
| 115 |
Opaque token representing position in the stream. If not provided, stream will start from the latest events. |
| 116 |
|
| 117 |
from_timestamp : typing.Optional[str] |
| 118 |
RFC-3339 timestamp indicating where to start streaming events from. This should only be used on the initial query when a cursor may not be available. Subsequent requests should use the cursor (from) as it will be more accurate. |
| 119 |
|
| 120 |
event_type : typing.Optional[typing.Union[EventStreamSubscribeEventsEventTypeEnum, typing.Sequence[EventStreamSubscribeEventsEventTypeEnum]]] |
| 121 |
Event type(s) to listen for. Specify multiple times for multiple types (e.g., ?event_type=user.created&event_type=user.updated). If not provided, all event types will be streamed. |
| 122 |
|
| 123 |
request_options : typing.Optional[RequestOptions] |
| 124 |
Request-specific configuration. |
| 125 |
|
| 126 |
Yields |
| 127 |
------ |
| 128 |
typing.AsyncIterator[EventStreamSubscribeEventsResponseContent] |
| 129 |
Event stream successfully established. |
| 130 |
|
| 131 |
Examples |
| 132 |
-------- |
| 133 |
import asyncio |
| 134 |
|
| 135 |
from auth0 import AsyncAuth0 |
| 136 |
|
| 137 |
client = AsyncAuth0( |
| 138 |
token="YOUR_TOKEN", |
| 139 |
) |
| 140 |
|
| 141 |
|
| 142 |
async def main() -> None: |
| 143 |
response = await client.events.subscribe( |
| 144 |
from_="from", |
| 145 |
from_timestamp="from_timestamp", |
| 146 |
event_type=["connection.created"], |
| 147 |
) |
| 148 |
async for chunk in response: |
| 149 |
yield chunk |
| 150 |
|
| 151 |
|
| 152 |
asyncio.run(main()) |
| 153 |
""" |
| 154 |
async with self._raw_client.subscribe( |
| 155 |
from_=from_, from_timestamp=from_timestamp, event_type=event_type, request_options=request_options |
| 156 |
) as r: |
| 157 |
async for _chunk in r.data: |
| 158 |
yield _chunk |