reflex


Namereflex JSON
Version 0.4.9 PyPI version JSON
download
home_pagehttps://reflex.dev
SummaryWeb apps in pure Python.
upload_time2024-04-23 16:55:48
maintainerNone
docs_urlNone
authorNikhil Rao
requires_python<4.0,>=3.8
licenseApache-2.0
keywords web framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ```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)
![tests](https://github.com/pynecone-io/pynecone/actions/workflows/integration.yml/badge.svg)
![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)

---

# 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.8+):

```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.

&nbsp;

<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>

&nbsp;

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"),
            rx.cond(
                State.processing,
                rx.chakra.circular_progress(is_indeterminate=True),
                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.

### **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 show the circular progress and 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) &nbsp; |  &nbsp; 🗞️ [Blog](https://reflex.dev/blog) &nbsp; |  &nbsp; 📱 [Component Library](https://reflex.dev/docs/library) &nbsp; |  &nbsp; 🖼️ [Gallery](https://reflex.dev/docs/gallery) &nbsp; |  &nbsp; 🛸 [Deployment](https://reflex.dev/docs/hosting/deploy-quick-start)  &nbsp;   

</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.8",
    "maintainer_email": null,
    "keywords": "web, framework",
    "author": "Nikhil Rao",
    "author_email": "nikhil@reflex.dev",
    "download_url": "https://files.pythonhosted.org/packages/ae/98/5e874f904928987a2dcd691631bd8d0ac1e694d9b54a479688dce82b08bd/reflex-0.4.9.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![tests](https://github.com/pynecone-io/pynecone/actions/workflows/integration.yml/badge.svg)\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)\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.8+):\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&nbsp;\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&nbsp;\n\nHere is the complete code to create this. This is all done in one Python file!\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\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(\"Generate Image\", on_click=State.get_image, width=\"25em\"),\n            rx.cond(\n                State.processing,\n                rx.chakra.circular_progress(is_indeterminate=True),\n                rx.cond(\n                    State.complete,\n                    rx.image(src=State.image_url, width=\"20em\"),\n                ),\n            ),\n            align=\"center\",\n        ),\n        width=\"100%\",\n        height=\"100vh\",\n    )\n\n\n# Add state and page to the app.\napp = rx.App()\napp.add_page(index, title=\"Reflex:DALL-E\")\n```\n\n## Let's break this down.\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 show the circular progress and 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) &nbsp; |  &nbsp; \ud83d\uddde\ufe0f [Blog](https://reflex.dev/blog) &nbsp; |  &nbsp; \ud83d\udcf1 [Component Library](https://reflex.dev/docs/library) &nbsp; |  &nbsp; \ud83d\uddbc\ufe0f [Gallery](https://reflex.dev/docs/gallery) &nbsp; |  &nbsp; \ud83d\udef8 [Deployment](https://reflex.dev/docs/hosting/deploy-quick-start)  &nbsp;   \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.4.9",
    "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": "e9e21e4776b3ed54b92b4d31c5183f20815935217d39064173ec69b15c7e2164",
                "md5": "70cd1a5015861ed0c04050feef9d57ce",
                "sha256": "7210a1af9e50db97866619f8c9a18f9cde25c08890f96a7d33e00a9a8bfc6074"
            },
            "downloads": -1,
            "filename": "reflex-0.4.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "70cd1a5015861ed0c04050feef9d57ce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 780524,
            "upload_time": "2024-04-23T16:55:46",
            "upload_time_iso_8601": "2024-04-23T16:55:46.073413Z",
            "url": "https://files.pythonhosted.org/packages/e9/e2/1e4776b3ed54b92b4d31c5183f20815935217d39064173ec69b15c7e2164/reflex-0.4.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae985e874f904928987a2dcd691631bd8d0ac1e694d9b54a479688dce82b08bd",
                "md5": "4d737684c3b3b59fa23684b8ab52c973",
                "sha256": "d549f29a2e14e23dd28ecfb04fb95f0f032fcab6b9176c84b836b6b74c5c6c97"
            },
            "downloads": -1,
            "filename": "reflex-0.4.9.tar.gz",
            "has_sig": false,
            "md5_digest": "4d737684c3b3b59fa23684b8ab52c973",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 474889,
            "upload_time": "2024-04-23T16:55:48",
            "upload_time_iso_8601": "2024-04-23T16:55:48.839658Z",
            "url": "https://files.pythonhosted.org/packages/ae/98/5e874f904928987a2dcd691631bd8d0ac1e694d9b54a479688dce82b08bd/reflex-0.4.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-23 16:55:48",
    "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"
}
        
Elapsed time: 0.24495s