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
### TL;DR
Updated the README with v2 component API documentation and improved development instructions.
### What changed?
- Restructured the main README to prominently feature both v1 and v2 component APIs
- Added code samples for both APIs with expandable sections
- Updated the quickstart section to use Cookiecutter and uv for generating new components
- Added information about pre-generated templates for easy browsing
- Added development install instructions with `-e` flag to all template READMEs
Copy file name to clipboardExpand all lines: README.md
+93-65Lines changed: 93 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,74 +10,102 @@ A Streamlit Component is made out of a Python API and a frontend (built using an
10
10
11
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
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`.
13
+
```python
14
+
import streamlit as st
75
15
76
-
## Examples
16
+
# Declare the component
17
+
my_component = st.components.v2.component(
18
+
"your-package.your_component",
19
+
js="index-*.js",
20
+
html='<div class="react-root"></div>',
21
+
)
22
+
23
+
# Use it directly or via a small wrapper
24
+
value = my_component(data={"name": "World"}, default={"num_clicks": 0})
See full examples in `templates/v1/template/` and `templates/v1/template-reactless/`.
77
70
78
-
See the `template-reactless` directory for a template that does not use [React](https://reactjs.org/).
71
+
## Supported template versions
72
+
73
+
This repo provides templates for both Streamlit Component APIs:
74
+
75
+
- v2: Uses `st.components.v2.component()` and `@streamlit/component-v2-lib`.
76
+
- v1: Uses `st.components.v1.component()` and `streamlit-component-lib`.
77
+
78
+
## Quickstart (generate a new component with Cookiecutter)
79
+
80
+
- 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.
81
+
- Generate from this template using Cookiecutter via `uvx`:
- Follow the interactive prompts to generate your project.
95
+
- Once created, follow the `README`in your new project to get started.
96
+
97
+
## Just browsing? Pre-generated outputs
98
+
99
+
If you want to quickly explore without running Cookiecutter, browse the pre-generated templates in this repo:
100
+
101
+
- v2 outputs: `templates/v2/template/` and `templates/v2/template-reactless/`
102
+
- v1 outputs: `templates/v1/template/` and `templates/v1/template-reactless/`
103
+
104
+
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.
105
+
106
+
## Examples
79
107
80
-
See the `examples` directory for examples on working with pandas DataFrames, integrating with third-party libraries, and more.
108
+
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