python convert to hmac sha256

import hmac
import hashlib
import base64
dig ='1234567890', msg=your_bytes_string, digestmod=hashlib.sha256).digest()
base64.b64encode(dig).decode()      # py3k-mode

Here is what the above code is Doing:
1. The function takes two arguments: the secret key and the message.
2. The digestmod argument specifies the hash function to use.
3. The .digest() method returns the digest of the message as a byte string.
4. The base64.b64encode() function takes the byte string and returns a base64 encoded ASCII string.
5. The .decode() method converts the ASCII string to a unicode string.