+
+
+ # PyReact Framework
+
+ **A Python-based web framework that combines server-side rendering with client-side interactivity**
+
+ [](https://www.python.org/downloads/)
+ [](https://fastapi.tiangolo.com/)
+ [](LICENSE)
+
+
-Pyreact is a Python-based web framework that combines server-side rendering with client-side interactivity. It allows for the creation of dynamic web applications using the simplicity of Python.
+---
-## Table of Contents
+## 📖 Overview
-1. [Features](#features)
-2. [Installation](#installation)
-3. [Folder Structure](#folder-structure)
-4. [Quick Start](#quick-start)
-5. [Example App: Multi-feature Blog](#example-app-multi-feature-blog)
-6. [Detailed Feature Usage](#detailed-feature-usage)
+PyReact is a Python-based web framework that combines server-side rendering with client-side interactivity. It allows for the creation of dynamic web applications using the simplicity of Python, bringing a React-like component architecture to Python web development.
-## Features
+## 📋 Table of Contents
-- Component-based architecture
-- Server-side rendering
-- Client-side routing
-- Automatic state management
-- Event handling
-- Middleware and hooks
-- Error handling
-- Static file serving
-- Build mode with hot reloading
-- API integration
-- Component importing from separate files
+1. [Features](#-features)
+2. [Installation](#-installation)
+3. [Folder Structure](#-folder-structure)
+4. [Quick Start](#-quick-start)
+5. [Core Concepts](#-core-concepts)
+ - [Components](#components)
+ - [Routing](#routing)
+ - [State Management](#state-management)
+ - [Event Handling](#event-handling)
+6. [Example App: Multi-feature Blog](#-example-app-multi-feature-blog)
+7. [API Reference](#-api-reference)
+8. [Configuration](#-configuration)
+9. [Deployment](#-deployment)
+10. [Troubleshooting](#-troubleshooting)
+11. [Contributing](#-contributing)
+12. [License](#-license)
-## Installation
+## ✨ Features
-To use Pyreact, you need to have Python installed on your system. You can download this repository and install the required libraries using the following command:
+- **🧩 Component-Based Architecture**: Create reusable UI components with Python decorators
+- **⚡ Server-Side Rendering (SSR)**: Fast initial page loads with server-rendered HTML
+- **🔀 Client-Side Routing**: Seamless navigation without full page reloads
+- **🔄 Automatic State Management**: Built-in global state management system
+- **🎯 Event Handling**: Powerful event system with custom handlers
+- **🔌 Middleware & Hooks**: Request/response processing with before/after hooks
+- **❌ Error Handling**: Custom error handlers for graceful error management
+- **📁 Static File Serving**: Easy static asset management
+- **🔥 Hot Reloading**: Instant feedback during development with build mode
+- **🌐 API Integration**: RESTful API support with multiple HTTP methods
+- **📦 Modular Components**: Import components from separate files for better organization
+- **🎨 CSS Management**: Global and component-level CSS support
+- **🔌 WebSocket Support**: Real-time communication capabilities
+- **📝 Form Handling**: Easy form submission and validation
+## 📦 Installation
-```
+### Prerequisites
+
+- Python 3.7 or higher
+- pip (Python package installer)
+
+### Install Dependencies
+To use PyReact, you need to install the required dependencies:
+
+```bash
pip install fastapi uvicorn watchdog beautifulsoup4
+```
+
+### Clone the Repository
+```bash
+git clone https://github.com/mianjunaid1223/PyReact.git
+cd PyReact
```
-(Note: As this is a custom framework, you may need to package and distribute it separately)
+### Verify Installation
-##Folder Structure
+Run the example app to verify everything is working:
+
+```bash
+python app.py
+```
+
+Visit `http://127.0.0.1:3000` in your browser to see the PyReact demo.
+
+> **Note**: PyReact is currently a custom framework. Future releases may include pip package distribution.
+
+## 📁 Folder Structure
```
my_pyreact_app/
│
-├── app.py
-├── index.html
-├── pyreact.py
-├── static/
-│ ├── styles.css
-│ └── scripts.js
-└── components/
- ├── component1.py
- ├── component2.py
- └── component3.py
+├── app.py # Main application file with routes and configuration
+├── index.html # Base HTML template
+├── pyreact.py # Core PyReact framework code
+├── static/ # Static assets directory
+│ ├── styles.css # Global styles
+│ ├── pyreact.js # Client-side PyReact code
+│ └── PyReact-logo.png # Logo and other images
+└── components/ # Reusable component directory
+ ├── __init__.py # Package initializer
+ ├── Header.py # Example: Header component
+ ├── Footer.py # Example: Footer component
+ ├── BlogPost.py # Example: BlogPost component
+ └── image.py # Example: Image component
```
-## Quick Start
+### Key Files Explained
+
+- **`app.py`**: Entry point of your application. Define routes, components, and app configuration here.
+- **`pyreact.py`**: The core framework file containing PyReact classes and methods.
+- **`index.html`**: Base HTML template that PyReact uses to render components.
+- **`static/`**: Directory for static files (CSS, JavaScript, images, fonts, etc.)
+- **`components/`**: Directory containing reusable component definitions.
+
+## 🚀 Quick Start
-1. Create a new directory for your project and set up the folder structure as shown above.
-2. Create your main `app.py` file:
+### Step 1: Create Your First Component
+
+Create a simple component in `app.py`:
```python
from pyreact import pyreact, component, route
-from components.Header import Header
-from components.Footer import Footer
@component
-def App(props):
+def HelloWorld(props):
+ name = props.get('name', 'World')
return f"""
- {Header(title="My Pyreact App")}
- {props.get('children', 'Welcome to Pyreact!')}
- {Footer()}
+
+
Hello, {name}!
+
Welcome to PyReact Framework
+
"""
+```
+
+### Step 2: Define a Route
+Map a URL to your component:
+
+```python
@route("/")
async def home(request):
- return App(children="
Hello, Pyreact!
")
+ return HelloWorld(name="PyReact Developer")
+```
+### Step 3: Initialize and Run
+
+Set up the PyReact application:
+
+```python
+# Create the app instance
app = pyreact.create_app()
+# Configure settings
+pyreact.set_static_dir("static")
+pyreact.add_global_css_file("styles.css")
+pyreact.set_mode("build") # Enable hot reloading
+
+# Run the application
if __name__ == "__main__":
- pyreact.set_mode("build") # or "use"
- pyreact.run("app:app", host="127.0.0.1", port=8000, reload=True)
+ import uvicorn
+ uvicorn.run("app:app", host="127.0.0.1", port=3000, reload=True)
```
-3. Run your app:
+### Step 4: Run Your App
-```
+```bash
python app.py
```
-Visit `http://127.0.0.1:8000` in your browser to see your Pyreact app in action!
+Visit `http://127.0.0.1:3000` in your browser to see your PyReact app in action!
+
+## 💡 Core Concepts
+
+### Components
+
+Components are the building blocks of PyReact applications. They are reusable, isolated pieces of UI that can be composed together.
+
+#### Creating a Component
+
+Use the `@component` decorator to create a component:
+
+```python
+from pyreact import component
+
+@component
+def Button(props):
+ text = props.get('text', 'Click Me')
+ color = props.get('color', 'blue')
+ return f"""
+
+ """
+```
+
+#### Using Components
+
+Components can be used within other components:
+
+```python
+@component
+def App(props):
+ return f"""
+
"
+
+@route("/post/")
+async def blog_post(request, post_id):
+ # post_id is automatically converted to integer
+ return f"
Blog Post #{post_id}
"
+```
+
+#### HTTP Methods
+
+Support multiple HTTP methods on the same route:
+
+```python
+@route("/api/data", methods=["GET", "POST"])
+async def api_data(request):
+ if request.method == "GET":
+ return pyreact.jsonify(data=["item1", "item2"])
+ elif request.method == "POST":
+ data = await request.json()
+ return pyreact.jsonify(status="success", received=data)
+```
+
+### State Management
+
+PyReact includes a global state management system for sharing data across components.
+
+#### Global State
+
+```python
+from pyreact import pyreact
+
+# Initialize global state
+pyreact.global_state['user'] = {"name": "John", "logged_in": True}
+pyreact.global_state['posts'] = []
+
+# Access state in routes or components
+@route("/profile")
+async def profile(request):
+ user = pyreact.global_state.get('user', {})
+ return f"
"
+```
+
+#### Issue: WebSocket connection fails
+
+**Problem**: Real-time features not working
+
+**Solution**: Ensure WebSocket route is accessible
+```python
+# Check that your server allows WebSocket connections
+# If behind a proxy, configure WebSocket forwarding
+```
+
+### Debug Mode
+
+Enable detailed logging for debugging:
+
+```python
+import logging
+
+logging.basicConfig(level=logging.DEBUG)
+
+if __name__ == "__main__":
+ import uvicorn
+ uvicorn.run("app:app", host="127.0.0.1", port=3000, reload=True, log_level="debug")
+```
+
+## 🤝 Contributing
+
+We welcome contributions to PyReact! Here's how you can help:
+
+### Reporting Issues
+
+If you find a bug or have a feature request:
+
+1. Check if the issue already exists in [GitHub Issues](https://github.com/mianjunaid1223/PyReact/issues)
+2. If not, create a new issue with:
+ - Clear description of the problem
+ - Steps to reproduce
+ - Expected vs actual behavior
+ - Your environment (Python version, OS, etc.)
+
+### Contributing Code
+
+1. **Fork the repository**
+ ```bash
+ git clone https://github.com/mianjunaid1223/PyReact.git
+ cd PyReact
+ ```
+
+2. **Create a feature branch**
+ ```bash
+ git checkout -b feature/your-feature-name
+ ```
+
+3. **Make your changes**
+ - Write clean, documented code
+ - Follow existing code style
+ - Add tests if applicable
+
+4. **Test your changes**
+ ```bash
+ python app.py
+ # Test the functionality
+ ```
+
+5. **Commit and push**
+ ```bash
+ git add .
+ git commit -m "Add: your feature description"
+ git push origin feature/your-feature-name
+ ```
+
+6. **Create a Pull Request**
+ - Go to the repository on GitHub
+ - Click "New Pull Request"
+ - Describe your changes
+
+### Development Guidelines
+
+- Follow PEP 8 style guidelines
+- Write clear, descriptive commit messages
+- Document new features in the README
+- Keep changes focused and atomic
+- Test thoroughly before submitting
+
+## 📄 License
+
+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
+
+## 🙏 Acknowledgments
+
+- Built with [FastAPI](https://fastapi.tiangolo.com/)
+- Inspired by React's component architecture
+- Uses [Uvicorn](https://www.uvicorn.org/) as the ASGI server
+- Styling with [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/)
+
+## 📞 Support
+
+- **Documentation**: [GitHub Repository](https://github.com/mianjunaid1223/PyReact)
+- **Issues**: [GitHub Issues](https://github.com/mianjunaid1223/PyReact/issues)
+- **Discussions**: [GitHub Discussions](https://github.com/mianjunaid1223/PyReact/discussions)
-1. **Components**: Create reusable components using the `@component` decorator.
-2. **Routing**: Define routes using the `@route` decorator.
-3. **State Management**: Use `pyreact.global_state` to manage application state.
-4. **Event Handling**: Create event handlers with `@pyreact.event_handler`.
-5. **Component Tag**: Use `` tags to dynamically load components.
-6. **Middleware and Hooks**: Use `@pyreact.before_request` and `@pyreact.after_request` for request processing.
-7. **Error Handling**: Define custom error handlers with `@pyreact.errorhandler`.
-8. **Static Files**: Serve static files from the `static` directory.
-9. **Build Mode**: Enable hot reloading with `pyreact.set_mode("build")`.
-10. **API Integration**: Create API endpoints using the `@route` decorator with different HTTP methods.
+---
-This README provides a comprehensive guide to using the Pyreact framework, including an example blog application that demonstrates all of its features. Users can use this as a starting point to build their own Pyreact applications.
+
+ Made with ❤️ by the PyReact Team
+
+ **[⭐ Star us on GitHub](https://github.com/mianjunaid1223/PyReact)**
+