Session
Index
Errors
error_score
Get the current error score.
Methods
__eq__
Compare two sessions for equality.
Parameters
optionalkeyword-onlyother: object
Returns bool
__init__
A default constructor.
Parameters
optionalkeyword-onlyid: str | None = None
Unique identifier for the session, autogenerated if not provided.
optionalkeyword-onlymax_age: timedelta = timedelta(minutes=50)
Time duration after which the session expires.
optionalkeyword-onlyuser_data: dict | None = None
Custom user data associated with the session.
optionalkeyword-onlymax_error_score: float = 3.0
Threshold score beyond which the session is considered blocked.
optionalkeyword-onlyerror_score_decrement: float = 0.5
Value by which the error score is decremented on successful operations.
optionalkeyword-onlycreated_at: datetime | None = None
Timestamp when the session was created, defaults to current UTC time if not provided.
optionalkeyword-onlyusage_count: int = 0
Number of times the session has been used.
optionalkeyword-onlymax_usage_count: int = 50
Maximum allowable uses of the session before it is considered expired.
optionalkeyword-onlyerror_score: float = 0.0
Current error score of the session.
optionalkeyword-onlycookies: dict | None = None
Cookies associated with the session.
optionalkeyword-onlyblocked_status_codes: list | None = None
HTTP status codes that indicate a session should be blocked.
Returns None
__repr__
Get a string representation.
Returns str
from_model
Create a new instance from a SessionModel.
Parameters
optionalkeyword-onlymodel: SessionModel
Returns Session
get_state
Parameters
optionalkeyword-onlyas_dict: Literal[true]
Returns dict
get_state
Parameters
optionalkeyword-onlyas_dict: Literal[false]
Returns SessionModel
get_state
Retrieve the current state of the session either as a model or as a dictionary.
Parameters
optionalkeyword-onlyas_dict: bool = False
Returns SessionModel | dict
is_blocked_status_code
Evaluate whether a session should be retired based on the received HTTP status code.
Parameters
optionalkeyword-onlystatus_code: int
The HTTP status code received from a server response.
optionalkeyword-onlyadditional_blocked_status_codes: list[int] | None = None
Optional additional status codes that should trigger session retirement.
Returns bool
mark_bad
Mark the session as bad after an unsuccessful session usage.
Returns None
mark_good
Mark the session as good. Should be called after a successful session usage.
Returns None
retire
Retire the session by setting the error score to the maximum value.
This method should be used if the session usage was unsuccessful and you are sure that it is because of the session configuration and not any external matters. For example when server returns 403 status code. If the session does not work due to some external factors as server error such as 5XX you probably want to use
mark_bad
method.Returns None
Properties
cookies
Get the cookies.
expires_at
Get the expiration datetime of the session.
id
Get the session ID.
is_blocked
Indicate whether the session is blocked based on the error score..
is_expired
Indicate whether the session is expired based on the current time.
is_max_usage_count_reached
Indicate whether the session has reached its maximum usage limit.
is_usable
Determine if the session is usable for next requests.
usage_count
Get the current usage count.
user_data
Get the user data.
Session object represents a single user session.
Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions. You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint. Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.