reflex-dev/reflex

GitHub: reflex-dev/reflex

Reflex 是一个纯 Python 全栈 Web 框架,让开发者无需编写 JavaScript 即可构建并部署高性能、可定制的 Web 应用。

Stars: 28574 | Forks: 1743

Reflex Logo
### **✨ 纯 Python 构建高性能、可定制的 Web 应用。几秒钟即可部署。✨** [![PyPI 版本](https://badge.fury.io/py/reflex.svg)](https://badge.fury.io/py/reflex) ![versions](https://img.shields.io/pypi/pyversions/reflex.svg) [![文档](https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6)](https://reflex.dev/docs/getting-started/introduction) [![PyPI 下载量](https://static.pepy.tech/badge/reflex)](https://pepy.tech/projects/reflex) [![Discord](https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord)](https://discord.gg/T5WSbC2YtQ) [![Twitter](https://img.shields.io/twitter/follow/getreflex)](https://x.com/getreflex)
# 简介 Reflex 是一个用于使用纯 Python 构建全栈 Web 应用的库。 主要特性: - **纯 Python** - 完全使用 Python 编写应用的前端和后端,无需学习 Javascript。 - **完全灵活** - Reflex 易于上手,并且可以扩展以支撑复杂的应用。 请查看我们的[架构页面](https://reflex.dev/blog/2024-03-21-reflex-architecture/#the-reflex-architecture)以了解 Reflex 的底层工作原理。 ## ⚙️ 安装 **重要提示:** 我们强烈建议使用虚拟环境,以确保 `reflex` 命令在你的 PATH 中可用。 ## 🥳 创建你的第一个应用 使用 [uv](https://docs.astral.sh/uv/) 创建一个项目,添加 Reflex,并启动开发服务器: ``` mkdir my_app_name cd my_app_name uv init uv add reflex uv run reflex init uv run reflex run ``` 你应该会看到你的应用在 http://localhost:3000 上运行。 现在你可以修改 `my_app_name/my_app_name.py` 中的源代码。Reflex 具有快速刷新功能,因此当你保存代码时可以立即看到更改。 ## 🫧 示例应用 使用 Reflex 在 Python 中构建一个图像生成应用:定义 UI,在类中管理状态,并从事件处理器中调用图像模型。
``` import reflex as rx import openai client = openai.AsyncOpenAI() class State(rx.State): prompt: str = "" image_url: str = "" processing: bool = False @rx.event def set_prompt(self, value: str): self.prompt = value @rx.event async def generate(self): self.processing = True yield response = await client.images.generate( model="gpt-image-1.5", prompt=self.prompt, ) self.image_url = f"data:image/png;base64,{response.data[0].b64_json}" self.processing = False def index(): return rx.vstack( rx.heading("Image Generator"), rx.input(placeholder="Enter a prompt...", on_change=State.set_prompt), rx.button("Generate", on_click=State.generate, loading=State.processing), rx.image(src=State.image_url), ) app = rx.App() app.add_page(index, title="Reflex:Image Generation") ``` ## 衷心感谢我们的所有贡献者:
标签:Python, Web框架, 后端开发, 无后门, 逆向工具