Metadata-Version: 2.4
Name: fastreact
Version: 0.1.1
Summary: FastAPI + React unified stack — zero config, one server, Python tracebacks in browser
Author-email: Mohammad Ramiz <your@email.com>
License: MIT
Project-URL: Homepage, https://github.com/RamizMohammad/fastreact
Project-URL: Issues, https://github.com/RamizMohammad/fastreact/issues
Project-URL: Portfolio, https://www.mohammadramiz.in
Project-URL: LinkedIn, https://www.linkedin.com/in/mohammad-ramiz
Project-URL: Source Code, https://github.com/RamizMohammad/fastreact
Keywords: fastreact,fastapi,react,fullstack,full-stack,fastapi-react,fastapi-frontend,fastapi-spa,fastapi-static,fastapi-vite,fastapi-fullstack,fastapi-react-integration,fastapi-serve-react,flask,flask-react,flask-spa,flask-frontend,flask-fullstack,flask-vite,react,reactjs,react-fastapi,react-python,react-flask,react-spa,react-vite,python-react,python-fullstack,python-spa,python-frontend,python-javascript,python-web,python-webdev,python-fullstack-framework,vite,uvicorn,starlette,spa,single-page-app,single-page-application,unified-stack,one-server,zero-config,hot-reload,hmr,dev-server,proxy,traceback,error-overlay,debug,developer-tools,react-router,client-side-routing,route-protection,production,docker,nginx,deployment,web,web-framework,web-app,webapp,javascript,typescript,frontend,backend,api,rest,rest-api,json,dx,developer-experience,cli,scaffold,boilerplate,starter,template
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: Framework :: Flask
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: JavaScript
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: User Interfaces
Classifier: Topic :: Software Development :: Build Tools
Classifier: Environment :: Web Environment
Classifier: Natural Language :: English
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.100.0
Requires-Dist: uvicorn>=0.23.0
Requires-Dist: httpx>=0.24.0
Provides-Extra: flask
Requires-Dist: flask>=2.3.0; extra == "flask"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: httpx>=0.24.0; extra == "dev"

<p align="center">
  <img src="https://raw.githubusercontent.com/RamizMohammad/fastreact/main/assets/logo.jpeg" width="150" />
</p>

# ⚡ FastReact

> **FastAPI + React = One Unified Stack**  
> Zero config. One server. Python tracebacks in your browser.

📖 **[Full Usage Guide →](USAGE.md)**

---

## What is FastReact?

FastReact is a Python library that bridges **FastAPI** and **React** into a single seamless stack.

- 🐍 FastAPI thinks it's serving Jinja templates — it's actually serving React
- ⚡ React thinks it's a normal Vite app — it's tunneled through FastAPI
- 🔴 Python errors appear as beautiful overlays in the browser (just like React's own error screen)
- 🔒 Python is the gatekeeper — React can only visit routes you register
- 🚀 One `uvicorn` instance serves everything — in dev AND production

---

## Install

```bash
# FastAPI + React
pip install fastreact

# Flask + React
pip install fastreact[flask]
```

---

## Quick Start

```bash
# 1. Scaffold React inside your FastAPI project
fastreact create frontend

# 2. Start both servers together with live request monitor
fastreact dev main:app --reload --call

# 3. Build for production
cd frontend && npm run build
uvicorn main:app --host 0.0.0.0 --port 8000
```

---

## Usage

```python
# main.py
from fastreact import FastReact

app = FastReact()

# React page routes — /api/ prefix — browser only
# Postman/curl → 405 Not Allowed
@app.get("/api/")
def home(): pass

@app.get("/api/users")
def users_page(): pass

# Normal data routes — everyone can call
@app.get("/users")
def get_users():
    return {"users": ["Alice", "Bob"]}
```

```bash
uvicorn main:app --reload
```

---

## Flask Support

```python
from fastreact import FlaskReact

app = FlaskReact()

@app.route("/api/users")
def users_page(): pass

@app.route("/users")
def get_users():
    return {"users": ["Alice", "Bob"]}

if __name__ == "__main__":
    app.run()
```

---

## Routing Rules

| Route | Browser | Postman/curl |
|-------|---------|--------------|
| `/api/users` (react prefix) | ✅ React renders | ❌ 405 Not Allowed |
| `/users` (normal route) | ✅ JSON | ✅ JSON |
| `/api/unknown` (unregistered) | ❌ 404 | ❌ 404 |

### Custom prefix

```python
app = FastReact(react_prefix="ui")   # /ui/... becomes React routes
```

---

## CLI

```
fastreact create <n>               Scaffold a new React (Vite) app
fastreact dev <file:app> [opts]    Start FastAPI + React dev servers together

  --reload                         Auto-restart on file save
  --port    <number>               Port number          default: 8000
  --host    <address>              Host address         default: 127.0.0.1
  --call                           Live HTTP request monitor
```

---

## Traceback Overlay

Python errors render as a beautiful browser overlay instead of JSON:

```
🔴 FastAPI Traceback — AttributeError
'NoneType' object has no attribute 'id'

File main.py, line 24, in get_user
    return user.id
    ^^^^^^^^^^^^^^
```

---

## Roadmap

- [x] FastAPI + React unified stack
- [x] Flask + React support
- [x] CLI dev mode — one command starts everything
- [x] Live request monitor (`--call`)
- [x] Python traceback overlay in browser
- [x] Route protection — browser-only React routes
- [x] Auto path normalization
- [ ] `--globalname` — instant public URL via SSH tunnel (v0.2.0)

---

## Documentation

| Guide | Description |
|-------|-------------|
| [USAGE.md](USAGE.md) | Full usage guide with all examples |
| [PUBLISH.md](PUBLISH.md) | How to publish to PyPI |

---

## Author

**Mohammad Ramiz**
- 🌐 [mohammadramiz.in](https://www.mohammadramiz.in)
- 💼 [LinkedIn](https://www.linkedin.com/in/mohammad-ramiz)
- 🐙 [GitHub](https://github.com/RamizMohammad)

---

## License

MIT
