Streamlit Code Editor

0.1.22 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import streamlit as st
from code_editor import code_editor

def main():
    st.set_page_config(layout="wide")
    st.title("My Streamlit Code Editor App")

    initial_code = """import pandas as pd

def greet(name):
    return f"Hello, {name}!"

print(greet("Streamlit"))
"""

    st.subheader("Edit your Python code:")
    response_dict = code_editor(initial_code, lang="python", key="my_editor")

    if response_dict and response_dict["type"] == "submit":
        st.write("You submitted the following code:")
        st.code(response_dict["text"], language="python")

if __name__ == "__main__":
    main()

view raw JSON →