Streamlit Code Editor is an active, community-driven component that integrates a React-Ace based code editor into Streamlit applications. It currently stands at version 0.1.22, offering features like custom themes, syntax highlighting for various languages, and customizable interface elements. The library maintains an active release cadence, with updates addressing performance, bug fixes, and new features.
pip install streamlit-code-editorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to embed a basic Python code editor in a Streamlit app. It uses `st.title` and `st.subheader` for layout and `code_editor` to render the interactive editor. The `key` argument is important for maintaining state across reruns, and the `response_dict` captures the editor's output, allowing submission handling.
To allow programmatic updates to the editor's content while keeping a consistent `key`, set `allow_reset=True` in the `code_editor` function call. `code_editor(initial_code, key='my_editor', allow_reset=True)`.
If real-time updates (e.g., on text change, blur, or selection) are desired, explicitly set the `response_mode` argument, e.g., `response_mode="debounce"` or `response_mode=["blur", "select"]`.
Always initialize `st.session_state` keys (e.g., `if 'key' not in st.session_state: st.session_state.key = initial_value`). When processing editor output, check `response_dict['id']` to ensure a new response has been sent before updating state or taking action.
Pass `allow_reset=True` to the `code_editor` function: `code_editor(initial_code, key='my_editor', allow_reset=True)`.
Ensure `st.session_state` is correctly initialized for any variable managing the editor's content. When reacting to the editor's output, use `response_dict['id']` to confirm a *new* response before processing and updating state, preventing reprocessing of stale values.
Ensure `st.session_state` variables are properly initialized and updated within callback functions or directly within the main script logic based on user interaction, then passed to the `code_editor` with `allow_reset=True`.