To encode string in `base64` format, you can use `base64` module for Python.
```Python
data = b"username:password"
encoded = base64.b64encode(data)
```
Keep in mind that `b64encode` takes bytes-like object instead of pure string, that's why there is `b` letter in line 1 saying this is byte-like object.
### See also
1. [[Base64 Encoding]]