Reflex Logo Reflex Logo
### **✨ 순수 Python으로 고성능 사용자 정의 웹앱을 만들어 보세요. 몇 초만에 배포 가능합니다. ✨** [![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) [![PyPI Downloads](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)
--- [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는 순수 Python으로 풀스택 웹 앱을 구축하기 위한 라이브러리입니다. 주요 기능: - **순수 Python** - 앱의 프론트엔드와 백엔드를 모두 Python으로 작성하며, Javascript를 배울 필요가 없습니다. - **완전한 유연성** - Reflex는 시작하기 쉽지만, 복잡한 앱으로도 확장할 수 있습니다. - **즉시 배포** - 앱을 빌드한 후 [단일 명령어](https://reflex.dev/docs/hosting/deploy-quick-start/)로 배포하거나 자체 서버에서 호스팅할 수 있습니다. Reflex가 내부적으로 어떻게 작동하는지 알아보려면 [아키텍처 페이지](https://reflex.dev/blog/2024-03-21-reflex-architecture/#the-reflex-architecture)를 참조하세요. ## ⚙️ 설치 터미널을 열고 실행하세요. (Python 3.10+ 필요): ```bash pip install reflex ``` ## 🥳 첫 앱 만들기 `reflex`를 설치하면, `reflex` 명령어 라인 도구도 설치됩니다. 새 프로젝트를 생성하여 설치가 성공적인지 확인합니다. (`my_app_name`을 프로젝트 이름으로 변경합니다.): ```bash mkdir my_app_name cd my_app_name reflex init ``` 이 명령어는 새 디렉토리에 템플릿 앱을 초기화합니다. 개발 모드에서 이 앱을 실행할 수 있습니다: ```bash reflex run ``` http://localhost:3000 에서 앱이 실행 됩니다. 이제 `my_app_name/my_app_name.py`에서 소스코드를 수정할 수 있습니다. Reflex는 빠른 새로고침을 지원하므로 코드를 저장할 때마다 즉시 변경 사항을 볼 수 있습니다. ## 🫧 예시 앱 예시를 살펴보겠습니다: [DALL·E](https://platform.openai.com/docs/guides/images/image-generation?context=node)를 중심으로 이미지 생성 UI를 만들어 보겠습니다. 간단하게 하기 위해 [OpenAI API](https://platform.openai.com/docs/api-reference/authentication)를 호출했지만, 이를 로컬에서 실행되는 ML 모델로 대체할 수 있습니다.  
A frontend wrapper for DALL·E, shown in the process of generating an image.
  이것이 완성된 코드입니다. 이 모든 것은 하나의 Python 파일에서 이루어집니다! ```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") ``` ## 하나씩 살펴보겠습니다.
Explaining the differences between backend and frontend parts of the DALL-E app.
### **Reflex UI** UI부터 시작해봅시다. ```python def index(): return rx.center( ... ) ``` `index` 함수는 앱의 프론트엔드를 정의합니다. `center`, `vstack`, `input`, `button`과 같은 다양한 컴포넌트를 사용하여 프론트엔드를 구축합니다. 컴포넌트들은 복잡한 레이아웃을 만들기 위해 서로 중첩될 수 있습니다. 그리고 키워드 인자를 사용하여 CSS의 모든 기능을 사용하여 스타일을 지정할 수 있습니다. Reflex는 시작하기 위한 [60개 이상의 기본 컴포넌트](https://reflex.dev/docs/library)를 제공하고 있습니다. 더 많은 컴포넌트를 추가하고 있으며, [자신만의 컴포넌트를 생성하는 것](https://reflex.dev/docs/wrapping-react/overview/)도 쉽습니다. ### **State** Reflex는 UI를 State 함수로 표현합니다. ```python class State(rx.State): """The app state.""" prompt = "" image_url = "" processing = False complete = False ``` state는 앱에서 변경될 수 있는 모든 변수(vars로 불림)와 이러한 변수를 변경하는 함수를 정의합니다. 여기서 state는 `prompt`와 `image_url`로 구성됩니다. 또한 `processing`과 `complete`라는 불리언 값이 있습니다. 이 값들은 이미지 생성 중 버튼을 비활성화할 때와, 결과 이미지를 표시할 때를 나타냅니다. ### **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 ``` State 내에서, state vars를 변경하는 이벤트 핸들러라고 불리는 함수를 정의합니다. 이벤트 핸들러는 Reflex에서 state를 변경하는 방법입니다. 버튼을 클릭하거나 텍스트 상자에 입력하는 것과 같이 사용자 동작에 응답하여 호출될 수 있습니다. 이러한 동작을 이벤트라고 합니다. DALL·E. 앱에는 OpenAI API에서 이미지를 가져오는 `get_image` 이벤트 핸들러가 있습니다. 이벤트 핸들러의 중간에 `yield`를 사용하면 UI가 업데이트됩니다. 그렇지 않으면 UI는 이벤트 핸들러의 끝에서 업데이트됩니다. ### **Routing** 마지막으로, 앱을 정의합니다. ```python app = rx.App() ``` 앱의 루트에서 index 컴포넌트로 페이지를 추가합니다. 또한 페이지 미리보기/브라우저 탭에 표시될 제목도 추가합니다. ```python app.add_page(index, title="DALL-E") ``` 여러 페이지를 추가하여 멀티 페이지 앱을 만들 수 있습니다. ## 📑 자료
📑 [문서](https://reflex.dev/docs/getting-started/introduction)   |   🗞️ [블로그](https://reflex.dev/blog)   |   📱 [컴포넌트 라이브러리](https://reflex.dev/docs/library)   |   🖼️ [템플릿](https://reflex.dev/templates/)   |   🛸 [배포](https://reflex.dev/docs/hosting/deploy-quick-start)  
## ✅ 상태 Reflex는 2022년 12월 Pynecone이라는 이름으로 출시되었습니다. 2025년부터 [Reflex Cloud](https://cloud.reflex.dev)가 출시되어 Reflex 앱을 위한 최상의 호스팅 경험을 제공합니다. 우리는 계속해서 개발하고 더 많은 기능을 구현할 예정입니다. Reflex는 매주 새로운 릴리즈와 기능을 제공합니다! 최신 정보를 확인하려면 :star: Star와 :eyes: Watch를 눌러 이 저장소를 확인하세요. ## 기여 우리는 모든 기여를 환영합니다! 아래는 Reflex 커뮤니티에 참여하는 좋은 방법입니다. - **Discord 참여**: 우리의 [Discord](https://discord.gg/T5WSbC2YtQ)는 Reflex 프로젝트에 대한 도움을 받고 기여하는 방법을 논의하는 최고의 장소입니다. - **GitHub Discussions**: 추가하고 싶은 기능이나 혼란스럽거나 해결이 필요한 것들에 대해 이야기하는 좋은 방법입니다. - **GitHub Issues**: [Issues](https://github.com/reflex-dev/reflex/issues)는 버그를 보고하는 훌륭한 방법입니다. 또한, 기존의 이슈를 해결하고 PR을 제출할 수 있습니다. 우리는 능력이나 경험에 상관없이 적극적으로 기여자를 찾고 있습니다. 기여하려면 [CONTRIBUTING.md](https://github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md)를 확인하세요. ## 모든 기여자들에게 감사드립니다: ## License Reflex는 오픈소스이며 [Apache License 2.0](/LICENSE)로 라이선스가 부여됩니다.