As of 2025, jupyter_server is the correct library to generate hash value of a string. I got a result with this config.
from jupyter_server.auth import passwd passwd('PASS')