ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) ssl_context.load_cert_chain(certfile="path/to/certfile", keyfile="path/to/keyfile") start_server = websockets.serve(echo, "localhost", 8765, ssl=ssl_context) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever()