You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+94-69Lines changed: 94 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,78 +6,103 @@ For complete information, please see the [Streamlit Components documentation](ht
6
6
7
7
## Overview
8
8
9
-
A Streamlit Component is made out of a Python API and a frontend (built using any web tech you prefer).
10
-
11
-
A Component can be used in any Streamlit app, can pass data between Python and frontend code, and can optionally be distributed on [PyPI](https://pypi.org/) for the rest of the world to use.
12
-
13
-
- Create a component's API in a single line of Python:
- Build the component's frontend out of HTML and JavaScript (or TypeScript, or ClojureScript, or whatever you fancy). React is supported, but not required:
- Ensure you have [Python 3.9+](https://www.python.org/downloads/), [Node.js](https://nodejs.org), and [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) installed.
50
-
- Clone this repo.
51
-
- Create a new Python virtual environment for the template:
52
-
```bash
53
-
$ cd template
54
-
$ python3 -m venv venv # create venv
55
-
$ . venv/bin/activate # activate venv
56
-
$ pip install streamlit # install streamlit
57
-
```
58
-
- Initialize and run the component template frontend:
59
-
```bash
60
-
$ cd template/my_component/frontend
61
-
$ npm install # Install npm dependencies
62
-
$ npm run start # Start the Vite dev server
63
-
```
64
-
- From a separate terminal, run the template's Streamlit app:
65
-
```bash
66
-
$ cd template
67
-
$ . venv/bin/activate # activate the venv you created earlier
68
-
$ pip install -e .# install template as editable package
69
-
$ streamlit run my_component/example.py # run the example
70
-
```
71
-
- If all goes well, you should see something like this:
72
-

73
-
- Modify the frontend code at `my_component/frontend/src/MyComponent.tsx`.
74
-
- Modify the Python code at `my_component/__init__.py`.
9
+
Components pair a Python API with a frontend. For new projects, we recommend the v2 API; the v1 API is also supported if you prefer it.
75
10
76
-
## Examples
11
+
```python
12
+
import streamlit as st
13
+
14
+
# Declare the component
15
+
my_component = st.components.v2.component(
16
+
"your-package.your_component",
17
+
js="index-*.js",
18
+
html='<div class="react-root"></div>',
19
+
)
20
+
21
+
# Use it directly or via a small wrapper
22
+
value = my_component(data={"name": "World"}, default={"num_clicks": 0})
See the `template-reactless` directory for a template that does not use [React](https://reactjs.org/).
67
+
See full examples in `templates/v1/template/` and `templates/v1/template-reactless/`.
68
+
69
+
## Supported template versions
70
+
71
+
This repo provides templates for both Streamlit Component APIs:
72
+
73
+
- v2: Uses `st.components.v2.component()` and `@streamlit/component-v2-lib`.
74
+
- v1: Uses `st.components.v1.component()` and `streamlit-component-lib`.
75
+
76
+
## Quickstart (generate a new component with Cookiecutter)
77
+
78
+
- Ensure you have [uv](https://docs.astral.sh/uv/), [Node.js](https://nodejs.org), and [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) installed.
79
+
- Generate from this template using Cookiecutter via `uvx`:
- Follow the interactive prompts to generate your project.
93
+
94
+
## Just browsing? Pre-generated outputs
95
+
96
+
If you want to quickly explore without running Cookiecutter, browse the pre-generated templates in this repo:
97
+
98
+
- v2 outputs: `templates/v2/template/` and `templates/v2/template-reactless/`
99
+
- v1 outputs: `templates/v1/template/` and `templates/v1/template-reactless/`
100
+
101
+
From within one of these folders, you can inspect the Python package layout and the `my_component/frontend` code. Refer to the template-level README for build instructions.
102
+
103
+
## Examples
79
104
80
-
See the `examples` directory for examples on working with pandas DataFrames, integrating with third-party libraries, and more.
105
+
See the `examples/v1/` directory for examples working with pandas DataFrames, integrating with third-party libraries, and more.
Copy file name to clipboardExpand all lines: cookiecutter/v2/{{ cookiecutter.package_name }}/README.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,14 @@
8
8
uv pip install {{ cookiecutter.package_name }}
9
9
```
10
10
11
+
### Development install (editable)
12
+
13
+
When developing this component locally, install it in editable mode so Streamlit picks up code changes without rebuilding a wheel. Run this from the directory that contains `pyproject.toml`:
Copy file name to clipboardExpand all lines: templates/v2/template-reactless/README.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,14 @@ Streamlit component that allows you to do X
8
8
uv pip install streamlit-custom-component
9
9
```
10
10
11
+
### Development install (editable)
12
+
13
+
When developing this component locally, install it in editable mode so Streamlit picks up code changes without rebuilding a wheel. Run this from the directory that contains `pyproject.toml`:
Copy file name to clipboardExpand all lines: templates/v2/template/README.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,14 @@ Streamlit component that allows you to do X
8
8
uv pip install streamlit-custom-component
9
9
```
10
10
11
+
### Development install (editable)
12
+
13
+
When developing this component locally, install it in editable mode so Streamlit picks up code changes without rebuilding a wheel. Run this from the directory that contains `pyproject.toml`:
0 commit comments