Chainlit#

Tip

Ploomber Cloud is a great platform to host your Chainlit apps, even Chainlit recommends us!

To deploy a Chainlit application in Ploomber Cloud you need:

  • A Ploomber Cloud account

  • Your application file (app.py)

  • A dependencies file (requirements.txt)

Testing locally#

To test your app, you can use this command:

pip install -r requirements.txt
chainlit run app.py --host=0.0.0.0 --port=5000 --headless

Now, open http://0.0.0.0:5000/ to see your app.

Deploy#

Deploy from the menu

Once you have all your files, create a zip file.

To deploy a Chainlit app from the deployment menu, follow these instructions:

Try an example

To download and deploy an example Chainlit application start by installing Ploomber Cloud and setting your API key:

pip install ploomber-cloud
ploomber-cloud key YOUR-KEY

Tip

If you don’t have an API key yet, follow the instructions here.

Now, download an example. It will prompt you for a location to download the app. To download in the current directory, just press enter.

ploomber-cloud examples chainlit/basic-app

Note

A full list of Chainlit example apps is available here.

You should see a confirmation with instructions on deploying your app. Now, navigate to your application:

cd location-you-entered/basic-app

Deploy from the CLI

Initialize and deploy your app with:

ploomber-cloud init
ploomber-cloud deploy --watch

Tip

To ensure your app doesn’t break on re-deployments, pin your dependencies.

Production deployments#

Ploomber has features to help you deploy production-ready Chainlit apps

Authentication#

Our integration with Auth0 allows you to easily add authentication to any Chainlit app. There’s no need to modify your Chainlit app code, only pass your Auth0 configuration parameters. Check out the sample app. In addition to the Auth0 parameters you also need to pass the CHAINLIT_AUTH_SECRET value. Refer to this section to learn more.

Features#

Ploomber Cloud supports many features to help you build Streamlit applications quickly!

Password protection#

Currently, our password authentication feature doesn’t work with Chainlit, however, we can still use Chainlit’s authentication feature.

First, download the sample code. The Dockerfile remains the same, the only change happens in the app.py.

During deployment, you need to provide three secrets:

CHAINTLIT_USERNAME="user"
CHAINTLIT_PASSWORD="somepassword"

CHAINLIT_AUTH_SECRET="somerandomstring"

CHAINLIT_AUTH_SECRET is a random string used to authenticate user tokens, you can generate one by executing the following command in your terminal:

python -c 'from secrets import token_hex; print(token_hex(16))'

Note

You can change CHAINLIT_AUTH_SECRET, but it’ll log out all your users.

Examples#