API Reference

itsdangerous

Sign and verify data with HMAC so tampering is detectable, including time-limited signed tokens.

Official Documentation ↗
CompatibilityThis documentation covers version v2.2.0. Check the official docs for the latest API surface.

Installation

pippip install itsdangerous

Methods

itsdangerous signs serialized data so a server can trust a value that passed through an untrusted client. It is the mechanism behind signed cookies, unsubscribe links, and password-reset tokens.

Integrity, not secrecy

The signature detects modification. The payload remains readable, so never place secrets inside a signed token that is handed to a browser.

Expiry and errors

loads(token, max_age=...) enforces a time limit. Catch SignatureExpired and BadSignature separately: expired tokens are a normal user flow, while a bad signature indicates tampering or a rotated key.

Errors

The official API reference declares the following error types:

Security

Official security statements captured from the package documentation:

  • 签名只能防篡改,数据对接收方可见;密钥必须保密且足够复杂 — “The receiver can see the data, but they can not modify it unless they also have your key. So if you keep the key secret and complex, you will be fine.” (source: https://itsdangerous.palletsprojects.com/en/stable/#, fetched 2026-11-08T16:03:08.4363995+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T16:03:08.4363995+08:00 via WebFetch 官方文档站(url_safe / serializer / exceptions / 首页).

FAQ

Is itsdangerous encryption?
No. It signs data with HMAC, which proves integrity and authenticity but does not hide the payload. Anyone holding the token can decode it; use encryption when confidentiality is required.
Where should the secret key come from?
Load it from an environment variable or a secret manager, and rotate it deliberately. A leaked key lets an attacker mint valid tokens for every user.
How do timed tokens work?
The token embeds a timestamp. loads(token, max_age=seconds) rejects tokens older than the limit, which is how password-reset and email-confirmation links expire.
Can I use this for passwords?
No. Signed tokens are not password hashes. Use a slow KDF such as argon2 or bcrypt for credentials and itsdangerous only for integrity-protected payloads.