You are looking for a signature function that uses a random part. It is e.g. possible to sign something using RSA-PSS and a private key. Then the token would be the combination of the public key and the signature. RSA-PSS differs from standard PKCS#1 v1.5 signatures that they contain this random component; PKCS#1 v1.5 delivers the same signature for identical input.
Note that RSA requires relatively large keys and signatures (2048 bit is the minimum by now) If you need a smaller token you may take a look at Elliptic Curves, but that's a lot harder to understand and implement. If you go that way you could use a named NIST curve such as P-256. That would make the minimum signature size about 3 to 4 times the EC key size (up to 128 bytes) instead of 512 bytes for RSA.
It seems PSS signatures are supported by M2Crypto, but as I don't program Python, you'll have to ask another question if you get stuck.