Skip to main content

create_access_token

Generates a JSON Web Token (JWT) for a given subject that expires after a specified time duration using a secret key and predefined algorithm.

def create_access_token(
subject: str | Any,
expires_delta: timedelta
) - > string

Generates a signed JSON Web Token (JWT) for a specific subject that expires after a designated time interval. Use this to provide secure, time-limited authentication credentials for users or services.

Parameters

NameTypeDescription
subject`strAny`
expires_deltatimedeltaThe duration from the current UTC time until the token becomes invalid.

Returns

TypeDescription
stringA base64-encoded JWT string containing the subject and expiration claims, signed with the application's secret key.