Skip to main content
Answer

Simulating CDF Environment Locally for Streamlit App

  • May 13, 2025
  • 6 replies
  • 93 views

Hi,

I'm developing a Streamlit app using the standard Streamlit library. However, I’ve noticed that the app behaves differently on my local machine compared to its deployment in CDF, likely due to additional configurations or dependencies used in CDF.

Could someone guide me on how to replicate the CDF environment locally to ensure consistent behavior?

Thanks

Best answer by Everton Colling

Hi ​@Tausif Sayyad,

The key difference is that CDF's Streamlit feature is based on stlite, which runs Python code in the browser using Pyodide (WebAssembly), while your local Streamlit most likely runs on CPython. This creates some fundamental differences in how code executes:

Pyodide Streamlit (stlite):

  • Runs entirely in the browser using a single-threaded event loop
  • Synchronous blocking operations (like your some_heavy_task()) prevent components from rendering until they complete
  • Requires async patterns for long-running tasks to allow UI updates

CPython Streamlit:

  • Runs on CPython with proper threading support
  • Components can render while background tasks execute

To get your components to appear while tasks are running in CDF, you'll need to convert your heavy tasks to use async/await patterns. You can check more information about stlite and its differences from standard Streamlit on the stlite documentation which explains these concepts and has examples on how to implement some async/await patterns that allow rendering of spinners and loading components.

6 replies

Forum|alt.badge.img+1

Hi,

How does it behave differently? In CDF, the following dependencies are installed for Streamlit: 

Don’t mind the version numbers, I need those for my current app to work properly :)

 


Anders Hafreager
Practitioner

To add on what Espen said, when you run locally you should at least have the same version of the `cognite-sdk`, and you do not need the `pyodide-http` package as it is only needed in our Streamlit runtime. Other than that, the authentication is different since we have a built-in method that reads your credentials from Fusion. What you could do here is to have a function called `get_client` and have a conditional.

The list of packages can be found by running

import micropip
st.write(micropip.list())

but some of the versions here are hard coded to 1.0.0 and installed in the Pyodide runtime so you can’t install those versions exactly. But you should be able to get pretty close to the similar environment.

But because I’m curious, what are the main behaviour differences you see?


  • Author
  • Seasoned
  • May 13, 2025

Hi

I've noticed that some of my Streamlit components are not rendering until all tasks below them are completed when deployed in CDF. However, on my local machine, the components appear even while the tasks below them are still in progress.
For example:

st.data_editor(some_data)
some_heavy_task()

Data Editor component does not appear until the some_heavy_task() call is completed when deployed in CDF. However, when I run the same code on my local machine, the component appears even while some_heavy_task() is still in progress.

Please help me to simulate this behaviour.

Thanks


  • Author
  • Seasoned
  • May 15, 2025

Hi,
Can someone please help me?

Thanks


Everton Colling
Seasoned Practitioner
Forum|alt.badge.img
  • Seasoned Practitioner
  • Answer
  • May 15, 2025

Hi ​@Tausif Sayyad,

The key difference is that CDF's Streamlit feature is based on stlite, which runs Python code in the browser using Pyodide (WebAssembly), while your local Streamlit most likely runs on CPython. This creates some fundamental differences in how code executes:

Pyodide Streamlit (stlite):

  • Runs entirely in the browser using a single-threaded event loop
  • Synchronous blocking operations (like your some_heavy_task()) prevent components from rendering until they complete
  • Requires async patterns for long-running tasks to allow UI updates

CPython Streamlit:

  • Runs on CPython with proper threading support
  • Components can render while background tasks execute

To get your components to appear while tasks are running in CDF, you'll need to convert your heavy tasks to use async/await patterns. You can check more information about stlite and its differences from standard Streamlit on the stlite documentation which explains these concepts and has examples on how to implement some async/await patterns that allow rendering of spinners and loading components.


  • Author
  • Seasoned
  • May 16, 2025

Hi ​@Everton Colling ,

Thank you for the clarification. I am able to simulate the same behavior after using stlite.

Thanks,
Tausif Sayyad