Generate a random password
Generate a random token with secrets.token_urlsafe. The argument counts bytes, not characters, so 16 bytes give a 22 character string, and random is not for this.
You need a random password, API key or reset token, and random is the wrong module for it.
import secrets, string
token = secrets.token_urlsafe(16)
print(len(token), set(token) <= set(string.ascii_letters + string.digits + "-_"))
alphabet = string.ascii_letters + string.digits
password = "".join(secrets.choice(alphabet) for _ in range(20))
print(len(password), password.isalnum())22 True
20 Truesecrets draws from the operating system's secure random source, which is what the secrets documentation recommends for credentials. token_urlsafe(n) takes n random bytes and encodes them in base64 using only URL safe characters, so 16 bytes become 22 characters, and the check confirms the alphabet. secrets.choice picks uniformly from an alphabet you control, for a password with a fixed length.
The generated values are random, so the output only shows their length and character set. The random module is a predictable generator and must not make secrets. A token is only as long as its bytes: 16 bytes carry 128 bits, which is enough for a session or reset token. Store it hashed, not in plain text.