How to Create A Fake Certificate Authority And Generate TLS Certs for FastAPI

You just created a world-changing webservice with the rave of the moment Python framework (FastAPI) and want to test how it will work with HTTPS in production?

Use trustme to create a local certificate authority (CA) that you can use to generate fake TLS certificates.


You will be able to visit https://localhost:8000 or which was previously impossible.



At the root of your project, run:

Start your server using the certificates you just generated

Let’s confirm that it’s working


We would also like to access our webservice through the browser so we need to add the certificate authority to it.

Chrome Setup

Type: chrome://settings/certificates in your URL address bar and press enter.

  1. Click ‘Authorities’

  2. Click on the ‘Import’ button and import the client.pem file.

  3. Click on all the checkboxes.

Test in your browser

From the visible padlock, we can verify that everything is working as intended.

So go forth and take over the world! ✌