```diff
+ Searching for Pynecone? You are in the right repo. Pynecone has been renamed to Reflex. +
```
<div align="center">
<img src="https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/reflex_dark.svg#gh-light-mode-only" alt="Reflex Logo" width="300px">
<img src="https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/reflex_light.svg#gh-dark-mode-only" alt="Reflex Logo" width="300px">
<hr>
### **✨ Performant, customizable web apps in pure Python. Deploy in seconds. ✨**
[![PyPI version](https://badge.fury.io/py/reflex.svg)](https://badge.fury.io/py/reflex)
![versions](https://img.shields.io/pypi/pyversions/reflex.svg)
[![Documentation](https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6)](https://reflex.dev/docs/getting-started/introduction)
[![Discord](https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord)](https://discord.gg/T5WSbC2YtQ)
</div>
---
[English](https://github.com/reflex-dev/reflex/blob/main/README.md) | [简体中文](https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_cn/README.md) | [繁體中文](https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_tw/README.md) | [Türkçe](https://github.com/reflex-dev/reflex/blob/main/docs/tr/README.md) | [हिंदी](https://github.com/reflex-dev/reflex/blob/main/docs/in/README.md) | [Português (Brasil)](https://github.com/reflex-dev/reflex/blob/main/docs/pt/pt_br/README.md) | [Italiano](https://github.com/reflex-dev/reflex/blob/main/docs/it/README.md) | [Español](https://github.com/reflex-dev/reflex/blob/main/docs/es/README.md) | [한국어](https://github.com/reflex-dev/reflex/blob/main/docs/kr/README.md) | [日本語](https://github.com/reflex-dev/reflex/blob/main/docs/ja/README.md) | [Deutsch](https://github.com/reflex-dev/reflex/blob/main/docs/de/README.md) | [Persian (پارسی)](https://github.com/reflex-dev/reflex/blob/main/docs/pe/README.md) | [Tiếng Việt](https://github.com/reflex-dev/reflex/blob/main/docs/vi/README.md)
---
# Reflex
Reflex is a library to build full-stack web apps in pure Python.
Key features:
* **Pure Python** - Write your app's frontend and backend all in Python, no need to learn Javascript.
* **Full Flexibility** - Reflex is easy to get started with, but can also scale to complex apps.
* **Deploy Instantly** - After building, deploy your app with a [single command](https://reflex.dev/docs/hosting/deploy-quick-start/) or host it on your own server.
See our [architecture page](https://reflex.dev/blog/2024-03-21-reflex-architecture/#the-reflex-architecture) to learn how Reflex works under the hood.
## ⚙️ Installation
Open a terminal and run (Requires Python 3.9+):
```bash
pip install reflex
```
## 🥳 Create your first app
Installing `reflex` also installs the `reflex` command line tool.
Test that the install was successful by creating a new project. (Replace `my_app_name` with your project name):
```bash
mkdir my_app_name
cd my_app_name
reflex init
```
This command initializes a template app in your new directory.
You can run this app in development mode:
```bash
reflex run
```
You should see your app running at http://localhost:3000.
Now you can modify the source code in `my_app_name/my_app_name.py`. Reflex has fast refreshes so you can see your changes instantly when you save your code.
## 🫧 Example App
Let's go over an example: creating an image generation UI around [DALL·E](https://platform.openai.com/docs/guides/images/image-generation?context=node). For simplicity, we just call the [OpenAI API](https://platform.openai.com/docs/api-reference/authentication), but you could replace this with an ML model run locally.
<div align="center">
<img src="https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/dalle.gif" alt="A frontend wrapper for DALL·E, shown in the process of generating an image." width="550" />
</div>
Here is the complete code to create this. This is all done in one Python file!
```python
import reflex as rx
import openai
openai_client = openai.OpenAI()
class State(rx.State):
"""The app state."""
prompt = ""
image_url = ""
processing = False
complete = False
def get_image(self):
"""Get the image from the prompt."""
if self.prompt == "":
return rx.window_alert("Prompt Empty")
self.processing, self.complete = True, False
yield
response = openai_client.images.generate(
prompt=self.prompt, n=1, size="1024x1024"
)
self.image_url = response.data[0].url
self.processing, self.complete = False, True
def index():
return rx.center(
rx.vstack(
rx.heading("DALL-E", font_size="1.5em"),
rx.input(
placeholder="Enter a prompt..",
on_blur=State.set_prompt,
width="25em",
),
rx.button(
"Generate Image",
on_click=State.get_image,
width="25em",
loading=State.processing
),
rx.cond(
State.complete,
rx.image(src=State.image_url, width="20em"),
),
align="center",
),
width="100%",
height="100vh",
)
# Add state and page to the app.
app = rx.App()
app.add_page(index, title="Reflex:DALL-E")
```
## Let's break this down.
<div align="center">
<img src="docs/images/dalle_colored_code_example.png" alt="Explaining the differences between backend and frontend parts of the DALL-E app." width="900" />
</div>
### **Reflex UI**
Let's start with the UI.
```python
def index():
return rx.center(
...
)
```
This `index` function defines the frontend of the app.
We use different components such as `center`, `vstack`, `input`, and `button` to build the frontend. Components can be nested within each other
to create complex layouts. And you can use keyword args to style them with the full power of CSS.
Reflex comes with [60+ built-in components](https://reflex.dev/docs/library) to help you get started. We are actively adding more components, and it's easy to [create your own components](https://reflex.dev/docs/wrapping-react/overview/).
### **State**
Reflex represents your UI as a function of your state.
```python
class State(rx.State):
"""The app state."""
prompt = ""
image_url = ""
processing = False
complete = False
```
The state defines all the variables (called vars) in an app that can change and the functions that change them.
Here the state is comprised of a `prompt` and `image_url`. There are also the booleans `processing` and `complete` to indicate when to disable the button (during image generation) and when to show the resulting image.
### **Event Handlers**
```python
def get_image(self):
"""Get the image from the prompt."""
if self.prompt == "":
return rx.window_alert("Prompt Empty")
self.processing, self.complete = True, False
yield
response = openai_client.images.generate(
prompt=self.prompt, n=1, size="1024x1024"
)
self.image_url = response.data[0].url
self.processing, self.complete = False, True
```
Within the state, we define functions called event handlers that change the state vars. Event handlers are the way that we can modify the state in Reflex. They can be called in response to user actions, such as clicking a button or typing in a text box. These actions are called events.
Our DALL·E. app has an event handler, `get_image` to which get this image from the OpenAI API. Using `yield` in the middle of an event handler will cause the UI to update. Otherwise the UI will update at the end of the event handler.
### **Routing**
Finally, we define our app.
```python
app = rx.App()
```
We add a page from the root of the app to the index component. We also add a title that will show up in the page preview/browser tab.
```python
app.add_page(index, title="DALL-E")
```
You can create a multi-page app by adding more pages.
## 📑 Resources
<div align="center">
📑 [Docs](https://reflex.dev/docs/getting-started/introduction) | 🗞️ [Blog](https://reflex.dev/blog) | 📱 [Component Library](https://reflex.dev/docs/library) | 🖼️ [Templates](https://reflex.dev/templates/) | 🛸 [Deployment](https://reflex.dev/docs/hosting/deploy-quick-start)
</div>
## ✅ Status
Reflex launched in December 2022 with the name Pynecone.
As of February 2024, our hosting service is in alpha! During this time anyone can deploy their apps for free. See our [roadmap](https://github.com/reflex-dev/reflex/issues/2727) to see what's planned.
Reflex has new releases and features coming every week! Make sure to :star: star and :eyes: watch this repository to stay up to date.
## Contributing
We welcome contributions of any size! Below are some good ways to get started in the Reflex community.
- **Join Our Discord**: Our [Discord](https://discord.gg/T5WSbC2YtQ) is the best place to get help on your Reflex project and to discuss how you can contribute.
- **GitHub Discussions**: A great way to talk about features you want added or things that are confusing/need clarification.
- **GitHub Issues**: [Issues](https://github.com/reflex-dev/reflex/issues) are an excellent way to report bugs. Additionally, you can try and solve an existing issue and submit a PR.
We are actively looking for contributors, no matter your skill level or experience. To contribute check out [CONTIBUTING.md](https://github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md)
## All Thanks To Our Contributors:
<a href="https://github.com/reflex-dev/reflex/graphs/contributors">
<img src="https://contrib.rocks/image?repo=reflex-dev/reflex" />
</a>
## License
Reflex is open-source and licensed under the [Apache License 2.0](LICENSE).
Raw data
{
"_id": null,
"home_page": "https://reflex.dev",
"name": "reflex",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "web, framework",
"author": "Nikhil Rao",
"author_email": "nikhil@reflex.dev",
"download_url": "https://files.pythonhosted.org/packages/c8/cb/cc4b2dd3555e102a2d20537ab7f41db07df430c68235053876f9f57acd1a/reflex-0.6.5.tar.gz",
"platform": null,
"description": "```diff\n+ Searching for Pynecone? You are in the right repo. Pynecone has been renamed to Reflex. +\n```\n\n<div align=\"center\">\n<img src=\"https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/reflex_dark.svg#gh-light-mode-only\" alt=\"Reflex Logo\" width=\"300px\">\n<img src=\"https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/reflex_light.svg#gh-dark-mode-only\" alt=\"Reflex Logo\" width=\"300px\">\n\n<hr>\n\n### **\u2728 Performant, customizable web apps in pure Python. Deploy in seconds. \u2728**\n[![PyPI version](https://badge.fury.io/py/reflex.svg)](https://badge.fury.io/py/reflex)\n![versions](https://img.shields.io/pypi/pyversions/reflex.svg)\n[![Documentation](https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6)](https://reflex.dev/docs/getting-started/introduction)\n[![Discord](https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord)](https://discord.gg/T5WSbC2YtQ)\n</div>\n\n---\n\n[English](https://github.com/reflex-dev/reflex/blob/main/README.md) | [\u7b80\u4f53\u4e2d\u6587](https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_cn/README.md) | [\u7e41\u9ad4\u4e2d\u6587](https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_tw/README.md) | [T\u00fcrk\u00e7e](https://github.com/reflex-dev/reflex/blob/main/docs/tr/README.md) | [\u0939\u093f\u0902\u0926\u0940](https://github.com/reflex-dev/reflex/blob/main/docs/in/README.md) | [Portugu\u00eas (Brasil)](https://github.com/reflex-dev/reflex/blob/main/docs/pt/pt_br/README.md) | [Italiano](https://github.com/reflex-dev/reflex/blob/main/docs/it/README.md) | [Espa\u00f1ol](https://github.com/reflex-dev/reflex/blob/main/docs/es/README.md) | [\ud55c\uad6d\uc5b4](https://github.com/reflex-dev/reflex/blob/main/docs/kr/README.md) | [\u65e5\u672c\u8a9e](https://github.com/reflex-dev/reflex/blob/main/docs/ja/README.md) | [Deutsch](https://github.com/reflex-dev/reflex/blob/main/docs/de/README.md) | [Persian (\u067e\u0627\u0631\u0633\u06cc)](https://github.com/reflex-dev/reflex/blob/main/docs/pe/README.md) | [Ti\u1ebfng Vi\u1ec7t](https://github.com/reflex-dev/reflex/blob/main/docs/vi/README.md)\n\n---\n\n# Reflex\n\nReflex is a library to build full-stack web apps in pure Python.\n\nKey features:\n* **Pure Python** - Write your app's frontend and backend all in Python, no need to learn Javascript.\n* **Full Flexibility** - Reflex is easy to get started with, but can also scale to complex apps.\n* **Deploy Instantly** - After building, deploy your app with a [single command](https://reflex.dev/docs/hosting/deploy-quick-start/) or host it on your own server.\n\nSee our [architecture page](https://reflex.dev/blog/2024-03-21-reflex-architecture/#the-reflex-architecture) to learn how Reflex works under the hood.\n\n## \u2699\ufe0f Installation\n\nOpen a terminal and run (Requires Python 3.9+):\n\n```bash\npip install reflex\n```\n\n## \ud83e\udd73 Create your first app\n\nInstalling `reflex` also installs the `reflex` command line tool.\n\nTest that the install was successful by creating a new project. (Replace `my_app_name` with your project name):\n\n```bash\nmkdir my_app_name\ncd my_app_name\nreflex init\n```\n\nThis command initializes a template app in your new directory. \n\nYou can run this app in development mode:\n\n```bash\nreflex run\n```\n\nYou should see your app running at http://localhost:3000.\n\nNow you can modify the source code in `my_app_name/my_app_name.py`. Reflex has fast refreshes so you can see your changes instantly when you save your code.\n\n\n## \ud83e\udee7 Example App\n\nLet's go over an example: creating an image generation UI around [DALL\u00b7E](https://platform.openai.com/docs/guides/images/image-generation?context=node). For simplicity, we just call the [OpenAI API](https://platform.openai.com/docs/api-reference/authentication), but you could replace this with an ML model run locally.\n\n \n\n<div align=\"center\">\n<img src=\"https://raw.githubusercontent.com/reflex-dev/reflex/main/docs/images/dalle.gif\" alt=\"A frontend wrapper for DALL\u00b7E, shown in the process of generating an image.\" width=\"550\" />\n</div>\n\n \n\nHere is the complete code to create this. This is all done in one Python file!\n\n\n \n```python\nimport reflex as rx\nimport openai\n\nopenai_client = openai.OpenAI()\n\n\nclass State(rx.State):\n \"\"\"The app state.\"\"\"\n\n prompt = \"\"\n image_url = \"\"\n processing = False\n complete = False\n\n def get_image(self):\n \"\"\"Get the image from the prompt.\"\"\"\n if self.prompt == \"\":\n return rx.window_alert(\"Prompt Empty\")\n\n self.processing, self.complete = True, False\n yield\n response = openai_client.images.generate(\n prompt=self.prompt, n=1, size=\"1024x1024\"\n )\n self.image_url = response.data[0].url\n self.processing, self.complete = False, True\n\n\ndef index():\n return rx.center(\n rx.vstack(\n rx.heading(\"DALL-E\", font_size=\"1.5em\"),\n rx.input(\n placeholder=\"Enter a prompt..\",\n on_blur=State.set_prompt,\n width=\"25em\",\n ),\n rx.button(\n \"Generate Image\", \n on_click=State.get_image,\n width=\"25em\",\n loading=State.processing\n ),\n rx.cond(\n State.complete,\n rx.image(src=State.image_url, width=\"20em\"),\n ),\n align=\"center\",\n ),\n width=\"100%\",\n height=\"100vh\",\n )\n\n# Add state and page to the app.\napp = rx.App()\napp.add_page(index, title=\"Reflex:DALL-E\")\n```\n\n\n\n\n\n## Let's break this down.\n\n<div align=\"center\">\n<img src=\"docs/images/dalle_colored_code_example.png\" alt=\"Explaining the differences between backend and frontend parts of the DALL-E app.\" width=\"900\" />\n</div>\n\n\n### **Reflex UI**\n\nLet's start with the UI.\n\n```python\ndef index():\n return rx.center(\n ...\n )\n```\n\nThis `index` function defines the frontend of the app.\n\nWe use different components such as `center`, `vstack`, `input`, and `button` to build the frontend. Components can be nested within each other\nto create complex layouts. And you can use keyword args to style them with the full power of CSS.\n\nReflex comes with [60+ built-in components](https://reflex.dev/docs/library) to help you get started. We are actively adding more components, and it's easy to [create your own components](https://reflex.dev/docs/wrapping-react/overview/).\n\n### **State**\n\nReflex represents your UI as a function of your state.\n\n```python\nclass State(rx.State):\n \"\"\"The app state.\"\"\"\n prompt = \"\"\n image_url = \"\"\n processing = False\n complete = False\n\n```\n\nThe state defines all the variables (called vars) in an app that can change and the functions that change them.\n\nHere the state is comprised of a `prompt` and `image_url`. There are also the booleans `processing` and `complete` to indicate when to disable the button (during image generation) and when to show the resulting image.\n\n### **Event Handlers**\n\n```python\ndef get_image(self):\n \"\"\"Get the image from the prompt.\"\"\"\n if self.prompt == \"\":\n return rx.window_alert(\"Prompt Empty\")\n\n self.processing, self.complete = True, False\n yield\n response = openai_client.images.generate(\n prompt=self.prompt, n=1, size=\"1024x1024\"\n )\n self.image_url = response.data[0].url\n self.processing, self.complete = False, True\n```\n\nWithin the state, we define functions called event handlers that change the state vars. Event handlers are the way that we can modify the state in Reflex. They can be called in response to user actions, such as clicking a button or typing in a text box. These actions are called events.\n\nOur DALL\u00b7E. app has an event handler, `get_image` to which get this image from the OpenAI API. Using `yield` in the middle of an event handler will cause the UI to update. Otherwise the UI will update at the end of the event handler.\n\n### **Routing**\n\nFinally, we define our app.\n\n```python\napp = rx.App()\n```\n\nWe add a page from the root of the app to the index component. We also add a title that will show up in the page preview/browser tab.\n\n```python\napp.add_page(index, title=\"DALL-E\")\n```\n\nYou can create a multi-page app by adding more pages.\n\n## \ud83d\udcd1 Resources\n\n<div align=\"center\">\n\n\ud83d\udcd1 [Docs](https://reflex.dev/docs/getting-started/introduction) | \ud83d\uddde\ufe0f [Blog](https://reflex.dev/blog) | \ud83d\udcf1 [Component Library](https://reflex.dev/docs/library) | \ud83d\uddbc\ufe0f [Templates](https://reflex.dev/templates/) | \ud83d\udef8 [Deployment](https://reflex.dev/docs/hosting/deploy-quick-start) \n\n</div>\n\n\n## \u2705 Status\n\nReflex launched in December 2022 with the name Pynecone.\n\nAs of February 2024, our hosting service is in alpha! During this time anyone can deploy their apps for free. See our [roadmap](https://github.com/reflex-dev/reflex/issues/2727) to see what's planned.\n\nReflex has new releases and features coming every week! Make sure to :star: star and :eyes: watch this repository to stay up to date.\n\n## Contributing\n\nWe welcome contributions of any size! Below are some good ways to get started in the Reflex community.\n\n- **Join Our Discord**: Our [Discord](https://discord.gg/T5WSbC2YtQ) is the best place to get help on your Reflex project and to discuss how you can contribute.\n- **GitHub Discussions**: A great way to talk about features you want added or things that are confusing/need clarification.\n- **GitHub Issues**: [Issues](https://github.com/reflex-dev/reflex/issues) are an excellent way to report bugs. Additionally, you can try and solve an existing issue and submit a PR.\n\nWe are actively looking for contributors, no matter your skill level or experience. To contribute check out [CONTIBUTING.md](https://github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md)\n\n\n## All Thanks To Our Contributors:\n<a href=\"https://github.com/reflex-dev/reflex/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=reflex-dev/reflex\" />\n</a>\n\n## License\n\nReflex is open-source and licensed under the [Apache License 2.0](LICENSE).\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Web apps in pure Python.",
"version": "0.6.5",
"project_urls": {
"Documentation": "https://reflex.dev/docs/getting-started/introduction",
"Homepage": "https://reflex.dev",
"Repository": "https://github.com/reflex-dev/reflex"
},
"split_keywords": [
"web",
" framework"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "188bfaa0ef4075ae1a281613d436f2f3b12d48bc7aa645238c5054c7cfa4653c",
"md5": "642c6df67d91b5ae7e166dd091133a20",
"sha256": "ac8e981a0decae47b539561c59d289e676f700335cb0b8298bb68454e8ab3253"
},
"downloads": -1,
"filename": "reflex-0.6.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "642c6df67d91b5ae7e166dd091133a20",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 752992,
"upload_time": "2024-11-12T21:59:21",
"upload_time_iso_8601": "2024-11-12T21:59:21.575809Z",
"url": "https://files.pythonhosted.org/packages/18/8b/faa0ef4075ae1a281613d436f2f3b12d48bc7aa645238c5054c7cfa4653c/reflex-0.6.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c8cbcc4b2dd3555e102a2d20537ab7f41db07df430c68235053876f9f57acd1a",
"md5": "94ace4471f9fd204bfc8402a45b6c64e",
"sha256": "65a578a00471eb5be741abfdebb7c79b27390ad14ea1b884319be54375118a7d"
},
"downloads": -1,
"filename": "reflex-0.6.5.tar.gz",
"has_sig": false,
"md5_digest": "94ace4471f9fd204bfc8402a45b6c64e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 510345,
"upload_time": "2024-11-12T21:59:23",
"upload_time_iso_8601": "2024-11-12T21:59:23.453670Z",
"url": "https://files.pythonhosted.org/packages/c8/cb/cc4b2dd3555e102a2d20537ab7f41db07df430c68235053876f9f57acd1a/reflex-0.6.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-12 21:59:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "reflex-dev",
"github_project": "reflex",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "reflex"
}