atproto_client.client.methods_mixin.session¶
- class atproto_client.client.methods_mixin.session.AsyncSessionDispatchMixin(*args: Any, **kwargs: Any)¶
Bases:
object
- on_session_change(callback: Callable[[SessionEvent, Session], Coroutine[Any, Any, None]]) None ¶
Register a callback for session change event.
- Parameters:
callback – A callback to be called when the session changes. The callback must accept two arguments: event and session.
Note
Possible events: SessionEvent.IMPORT, SessionEvent.CREATE, SessionEvent.REFRESH.
Tip
You should save the session string to persistent storage on SessionEvent.CREATE and SessionEvent.REFRESN event.
Example
>>> from atproto import AsyncClient, SessionEvent, Session >>> >>> client = AsyncClient() >>> >>> async def on_session_change(event: SessionEvent, session: Session): >>> print(event, session) >>> >>> client.on_session_change(on_session_change)
- Returns:
None
- class atproto_client.client.methods_mixin.session.SessionDispatchMixin(*args: Any, **kwargs: Any)¶
Bases:
object
- on_session_change(callback: Callable[[SessionEvent, Session], None]) None ¶
Register a callback for session change event.
- Parameters:
callback – A callback to be called when the session changes. The callback must accept two arguments: event and session.
Example
>>> from atproto import Client, SessionEvent, Session >>> >>> client = Client() >>> >>> def on_session_change(event: SessionEvent, session: Session): >>> print(event, session) >>> >>> client.on_session_change(on_session_change)
- Returns:
None
- class atproto_client.client.methods_mixin.session.SessionMethodsMixin(*args: Any, **kwargs: Any)¶
Bases:
TimeMethodsMixin
- export_session_string() str ¶
Export session string.
Note
This method is useful for storing the session and reusing it later.
Warning
You should use it if you create the client instance often. Because of server rate limits for createSession. Rate limited by handle. 30/5 min, 300/day.
Attention
You must export session at the end of the Client`s life cycle! Alternatively, you can subscribe to the session change event. Use
on_session_change
to register handler.Example
>>> from atproto import Client >>> # the first time login with login and password >>> client = Client() >>> client.login('login', 'password') >>> session_string = client.export_session_string() >>> # store session_string somewhere. >>> # for example, in env and next time use it for login >>> client2 = Client() >>> client2.login(session_string=session_string)
- Returns:
Session string.
- Return type:
str