write_session#

write_session(filepath, state=None, sections=None, *, state_bytes=None)[source]#

Write a session file in the indexed format.

Parameters:
filepathstr

Destination file path.

statedict, optional

Session state dictionary to pickle.

sectionsdict, optional

Extra sections mapping names to (encoding, data) tuples. The "state" section is always written from state.

state_bytesbytes, optional

Pickled state written verbatim. Exactly one of state and state_bytes is required.

Notes

The file holds a 4-byte big-endian uint32 index length N, then N bytes of UTF-8 JSON index, then the section bytes. The index maps each section name to {"offset": int, "size": int, "encoding": str}, so readers seek directly to the section they need.