Skip to content

miniproto.session.strings.export_session_string

miniproto.session.strings.export_session_string

Section titled “miniproto.session.strings.export_session_string”
export_session_string(record_or_mapping: SessionRecord | Mapping[str, Any], *, format: Literal['miniproto', 'telethon', 'pyrogram'] = 'miniproto', passphrase: str | bytes | None = None, api_id: int | None = None, test_mode: bool | None = None) -> SessionString

Export a typed or decoded session record in a portable bearer format.

Parameters:

  • record_or_mapping (SessionRecord | Mapping[str, Any]) – A validated record or an already decoded record mapping.
  • format (Literal[‘miniproto’, ‘telethon’, ‘pyrogram’]) – Native miniproto (default), telethon, or pyrogram.
  • passphrase (str | bytes | None) – Optional native-only authenticated encryption using scrypt and AES-256-GCM.
  • api_id (int | None) – Required for Pyrogram when absent from record metadata.
  • test_mode (bool | None) – Required for Pyrogram when absent from record metadata.

Returns:

  • SessionString – A redacted-on-representation bearer session string.

Raises:

  • SessionEnvelopeError – If data, authentication material, limits, or format options are invalid.
  • TypeError – If the input is neither a record nor mapping.

Protected native strings authenticate and encrypt their payload. Plain native, Telethon, and Pyrogram outputs remain validated bearer encodings. Generic asynchronous storage is exported through Client.export_session_string; this layer deliberately only accepts already loaded state.