Flask-React
A Flask extension for server-side React component rendering with template-like functionality using Node.js.
Features
- 🚀 Server-side React component rendering with Node.js
- 🎯 Flask template integration (like Jinja2)
- 🔄 Support for conditions, loops, and data binding
- 📦 Component management system
- 🎨 Props passing and state management
- 🔧 Easy Flask integration
- ⚡ Fast Node.js-based rendering engine
Prerequisites
Node.js is required for server-side React rendering. Install Node.js before using this extension:
# Install Node.js (https://nodejs.org/)
# Verify installation:
node --version
npm --version
Installation
pip install flask-react-ssr
Quick Start
from flask import Flask
from flask_react import FlaskReact
app = Flask(__name__)
react = FlaskReact(app)
@app.route('/')
def home():
return react.render_component('HelloWorld', {
'name': 'Flask React',
'items': ['Feature 1', 'Feature 2', 'Feature 3']
})
Usage
Creating Components
Create React components in your components/ directory:
// components/HelloWorld.jsx
function HelloWorld({ name, items }) {
return (
<div>
<h1>Hello {name}!</h1>
{items && items.length > 0 && (
<ul>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
)}
</div>
);
}
Template-like Rendering
@app.route('/user/<username>')
def user_profile(username):
user_data = get_user(username)
return react.render_component('UserProfile', {
'user': user_data,
'is_authenticated': current_user.is_authenticated,
'permissions': get_user_permissions(username)
})
Conditional Rendering
// components/UserProfile.jsx
function UserProfile({ user, is_authenticated, permissions }) {
return (
<div>
<h1>{user.name}</h1>
{is_authenticated && (
<div className="authenticated-content">
<p>Welcome back!</p>
{permissions.includes('admin') && (
<button>Admin Panel</button>
)}
</div>
)}
{!is_authenticated && (
<div>
<p>Please log in to see more content.</p>
</div>
)}
</div>
);
}
Configuration
# Basic configuration
app.config['FLASK_REACT_COMPONENTS_DIR'] = 'components' # Components directory
app.config['FLASK_REACT_CACHE_COMPONENTS'] = True # Enable caching
app.config['FLASK_REACT_NODE_EXECUTABLE'] = 'node' # Node.js executable path
app.config['FLASK_REACT_NODE_TIMEOUT'] = 30 # Node.js process timeout
Setup for Development
- Install Node.js dependencies:
# Flask-React includes a package.json with all required dependencies
npm install
- Create components directory:
mkdir components
The package.json includes all necessary dependencies:
- React and ReactDOM for SSR
- Babel presets for JSX, TypeScript, and modern JavaScript
- Proper Node.js version requirements (16+)
Troubleshooting
Node.js Not Found
If you get "Node.js not found" errors:
- Ensure Node.js is installed and in your PATH
- Set the Node.js path explicitly:
app.config['FLASK_REACT_NODE_EXECUTABLE'] = '/path/to/node'
Component Not Found
- Check that your components are in the correct directory
- Verify file extensions (.jsx, .js, .ts, .tsx are supported)
- Ensure component names match file names
Rendering Timeout
- Increase timeout:
app.config['FLASK_REACT_NODE_TIMEOUT'] = 60 - Check for infinite loops in your components
License
MIT License
Metadata
Release files for flask-react-ssr 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_react_ssr-0.1.3.tar.gz | 17.0 kB | Without provenance | Details for flask_react_ssr-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_react_ssr-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for flask_react_ssr-0.1.3-py3-none-any.whl |
Total release size: 30.6 kB
Release files / flask_react_ssr-0.1.3.tar.gz
| Download URL | flask_react_ssr-0.1.3.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2f4f6a5f9834d8f7607b86103f3b6eb33edc4070272623be7f69fd3f735a37c
|
|
BLAKE2b-256 checksum How to use checksums |
db054e6fc2d18ae107c881528ce2d4b68ecf321b168c9fefdb7ff64c0a1b95c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / flask_react_ssr-0.1.3-py3-none-any.whl
| Download URL | flask_react_ssr-0.1.3-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f265e1e9639b3ac8fa22c25680ea055461b7cc43cd088332b7017d0885b4ce3
|
|
BLAKE2b-256 checksum How to use checksums |
8d61ade4a06425820a7c60cfa8be58a88b5a6a3051138b5e3d4bb970e35d4b6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Security for flask-react-ssr 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.