A Python web framework inspired by Next.js with file-based routing, SSR, and SSG and more
Project description
๐ NextPy Framework
The Python web framework with exact Next.js syntax! Build modern web applications with file-based routing, True JSX components, React-like hooks, server-side rendering (SSR), static site generation (SSG), and more - all with the same developer experience as Next.js but in Python!
๐ฏ Why NextPy?
- โ True JSX Syntax - Write exact Next.js JSX syntax in Python
- โ File-Based Routing - Automatic route discovery like Next.js
- โ
Server-Side Rendering - Full SSR support with
getServerSideProps - โ
Static Site Generation - Build static sites with
getStaticProps - โ Component Architecture - Reusable components with props and state
- โ Hot Reload - Instant development feedback
- โ TypeScript Support - Full type definitions and IntelliSense
- โ VS Code Extension - Dedicated extension for syntax highlighting
- โ Plugin System - Extensible architecture
- โ Debug Tools - Built-in debugging with detailed error pages
๐ Quick Start
Installation
# Install NextPy
pip install nextpy-framework
# Create new project
nextpy create my-app
# Navigate to project
cd my-app
# Start development server
nextpy dev
Your First NextPy App
Create pages/index.py:
def Home(props=None):
props = props or {}
title = props.get("title", "Welcome to NextPy")
message = props.get("message", "Your Python-powered web framework with True JSX")
return (
<div class="flex items-center justify-center min-h-screen bg-gradient-to-br from-blue-500 to-purple-600">
<div class="text-center text-white">
<h1 class="mb-4 text-5xl font-bold">{title}</h1>
<p class="text-xl">{message}</p>
<a href="/about" class="inline-block px-6 py-3 mt-8 font-semibold text-blue-600 transition-all duration-300 transform bg-white rounded-lg shadow-lg hover:bg-gray-100 hover:text-blue-700 hover:scale-105">
Learn More
</a>
</div>
</div>
)
def getServerSideProps(context):
return {
"props": {
"title": "Welcome to NextPy",
"message": "Your Python-powered web framework with True JSX"
}
}
default = Home
Visit http://localhost:8000 to see your app!
โ ๏ธ Important notes
- The framework now adds a set of security headers by default (CSP, X-Frame-Options, etc.) for safer deployments.
- You can request automatic Tailwind CSS compilation on startup by setting the
NEXTPY_AUTO_BUILD_TAILWIND=trueenvironment variable. This requiresnpmto be installed and will runnpm cifollowed bynpm run build:tailwind. - SQLAlchemy imports have been updated to avoid 2.0 deprecation warnings. If you see such warnings upgrade your dependencies or pin the versions as needed.
๐ Component Styles
NextPy supports 9 different component styles - choose what works best for you!
๐ฏ Style 1: Simple Function (Recommended)
def Home(props=None):
props = props or {}
return (
<div class="container">
<h1>Hello {props.get("name", "World")}</h1>
<button onClick="alert('Hello!')">Click Me</button>
</div>
)
default = Home
๐ฏ Style 2: With Server-Side Props
def Home(props=None):
return (
<div class="container">
<h1>{props.get("title", "Welcome")}</h1>
<p>{props.get("message", "Hello NextPy!")}</p>
</div>
)
def getServerSideProps(context):
return {
"props": {
"title": "Dynamic Title",
"message": "Server-rendered content!"
}
}
default = Home
๐ฏ Style 3: JSX Component Class
from nextpy.true_jsx import JSXComponent
@JSXComponent
class Home:
def __init__(self, props=None):
self.props = props or {}
def render(self):
return (
<div class="container">
<h1>{self.props.get("title", "Welcome")}</h1>
</div>
)
@staticmethod
def getServerSideProps(context):
return {
"props": {"title": "Class Component"}
}
default = Home
๐ฏ Style 4: Functional with Hooks
from nextpy.true_jsx import useState, useEffect
def Home(props=None):
const [count, setCount] = useState(0)
const [message, setMessage] = useState("Click the button!")
useEffect(() => {
if count > 5:
setMessage("You're clicking a lot!")
}, [count])
return (
<div class="container">
<h1>{message}</h1>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>
Click Me
</button>
</div>
)
default = Home
๐ฏ Style 5: Mixed Class + Function
class HomeComponent:
def __init__(self, props=None):
self.props = props or {}
def render(self):
return (
<div class="container">
<h1>{self.props.get("title", "Welcome")}</h1>
</div>
)
def Home(props=None):
component = HomeComponent(props)
return component.render()
default = Home
๐ฏ Style 6: With Children Components
from nextpy.true_jsx import JSXComponent
class Card(JSXComponent):
def render(self):
return (
<div class="p-6 bg-white rounded-lg shadow-lg">
{self.props.get("children", "")}
</div>
)
class Button(JSXComponent):
def render(self):
return (
<button
class={self.props.get("className", "bg-blue-500 text-white px-4 py-2 rounded")}
onClick={self.props.get("onClick", None)}
>
{self.props.get("children", "Click Me")}
</button>
)
def Home(props=None):
return (
<div class="container">
<Card>
<h1>Welcome to NextPy</h1>
<Button onClick={() => alert("Hello!")}>
Click Me!
</Button>
</Card>
</div>
)
default = Home
๐ฏ Style 7: Conditional Rendering
def Home(props=None):
is_logged_in = props.get("isLoggedIn", False)
user_name = props.get("userName", "Guest")
return (
<div class="container">
<h1>Welcome {user_name}!</h1>
{is_logged_in and (
<div>
<a href="/dashboard">Dashboard</a>
<a href="/profile">Profile</a>
</div>
)}
{!is_logged_in and (
<div>
<a href="/login">Login</a>
<a href="/register">Register</a>
</div>
)}
</div>
)
default = Home
๐ฏ Style 8: Lists and Mapping
def Home(props=None):
features = [
"โ
True JSX Syntax",
"โ
Component-Based Architecture",
"โ
Server-Side Rendering",
"โ
Hot Reload Support"
]
return (
<div class="container">
<h1>NextPy Features</h1>
<ul>
{features.map(feature => (
<li>{feature}</li>
))}
</ul>
</div>
)
default = Home
๐ฏ Style 9: Complex Layout
from nextpy.true_jsx import JSXComponent
class Layout(JSXComponent):
def render(self):
return (
<div class="min-h-screen bg-gray-100">
<nav class="bg-white shadow">
<div class="px-4 mx-auto max-w-7xl">
<div class="flex justify-between h-16">
<div class="flex items-center">
<h1 class="text-xl font-bold text-blue-600">NextPy</h1>
</div>
<div class="flex space-x-4">
{self.props.get("nav_items", [])}
</div>
</div>
</div>
</nav>
<main class="py-6 mx-auto max-w-7xl">
{self.props.get("children", "")}
</main>
</div>
)
def Navigation(props=None):
return (
<div class="flex space-x-4">
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact">Contact</a>
</div>
)
def Home(props=None):
return (
<Layout nav_items={<Navigation />}>
<div class="text-center">
<h1>Welcome to NextPy</h1>
<p>Build modern web apps with Python!</p>
</div>
</Layout>
)
default = Home
๐ฃ๏ธ Routing System
File-Based Routing
NextPy uses file-based routing just like Next.js:
pages/
โโโ index.py # โ /
โโโ about.py # โ /about
โโโ contact.py # โ /contact
โโโ blog/
โ โโโ index.py # โ /blog
โ โโโ post.py # โ /blog/post
โ โโโ [slug].py # โ /blog/:slug
โโโ users/
โ โโโ [id].py # โ /users/:id
โ โโโ [...all].py # โ /users/*
โโโ api/
โโโ hello.py # โ /api/hello
โโโ users/
โโโ [id].py # โ /api/users/:id
Dynamic Routes
# pages/blog/[slug].py
def BlogPost(props=None):
slug = props.get("slug", "")
return (
<div class="container">
<h1>Blog Post: {slug}</h1>
<p>This is a dynamic blog post.</p>
</div>
)
def getServerSideProps(context):
slug = context.get("params", {}).get("slug", "")
return {
"props": {"slug": slug}
}
default = BlogPost
Catch-All Routes
# pages/docs/[...path].py
def Docs(props=None):
path = props.get("path", [])
return (
<div class="container">
<h1>Documentation</h1>
<p>Path: {"/".join(path)}</p>
</div>
)
default = Docs
API Routes
# pages/api/hello.py
def get(request, params=None):
return {"message": "Hello from NextPy API!"}
def post(request, params=None):
data = await request.json()
return {"received": data, "message": "Data received!"}
# Or use handler function
def handler(request, params=None):
if request.method == "GET":
return {"message": "Hello!"}
elif request.method == "POST":
return {"status": "success"}
๐ง Data Fetching
Server-Side Rendering (SSR)
def BlogPost(props=None):
return (
<div class="container">
<h1>{props.get("title", "Loading...")}</h1>
<div>{props.get("content", "")}</div>
</div>
)
def getServerSideProps(context):
# Fetch data from database or API
slug = context.get("params", {}).get("slug", "")
# Simulate database call
posts = {
"hello-world": {
"title": "Hello World",
"content": "This is my first blog post!"
},
"nextpy-awesome": {
"title": "NextPy is Awesome",
"content": "Building web apps with Python and JSX!"
}
}
post = posts.get(slug, {"title": "Not Found", "content": "Post not found"})
return {
"props": {
"title": post["title"],
"content": post["content"],
"slug": slug
}
}
default = BlogPost
Static Site Generation (SSG)
def BlogPost(props=None):
return (
<div class="container">
<h1>{props.get("title", "")}</h1>
<div>{props.get("content", "")}</div>
</div>
)
def getStaticProps(context):
# Generate static props at build time
return {
"props": {
"title": "Static Blog Post",
"content": "This content is generated at build time!"
}
}
def getStaticPaths():
# Generate all possible paths
return {
"paths": [
{"params": {"slug": "hello-world"}},
{"params": {"slug": "nextpy-awesome"}},
{"params": {"slug": "python-jsx"}}
],
"fallback": False
}
default = BlogPost
๐จ Styling
CSS Classes
def Home(props=None):
return (
<div class="flex items-center justify-center min-h-screen bg-gradient-to-br from-blue-500 to-purple-600">
<div class="text-center text-white">
<h1 class="mb-4 text-4xl font-bold">Hello NextPy!</h1>
<p class="mb-8 text-xl">Build modern web apps with Python</p>
<button class="px-6 py-3 font-semibold text-blue-600 transition-colors bg-white rounded-lg hover:bg-gray-100">
Get Started
</button>
</div>
</div>
)
default = Home
Inline Styles
def Home(props=None):
return (
<div style="display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(to bottom right, #3B82F6, #9333EA);">
<div style="text-align: center; color: white;">
<h1 style="font-size: 2rem; font-weight: bold; margin-bottom: 1rem;">Hello NextPy!</h1>
<p style="font-size: 1.25rem; margin-bottom: 2rem;">Build modern web apps with Python</p>
</div>
</div>
)
default = Home
CSS Modules (Coming Soon)
# styles.module.css
.container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.title {
font-size: 2rem;
font-weight: bold;
color: #3B82F6;
}
# pages/index.py
import styles from "../styles.module.css"
def Home(props=None):
return (
<div class={styles.container}>
<h1 class={styles.title}>Hello NextPy!</h1>
</div>
)
default = Home
๐ Plugin System
NextPy has a powerful plugin system for extending functionality:
Creating Plugins
# plugins/my_plugin.py
from nextpy.plugins import Plugin, PluginContext, PluginResult
class MyPlugin(Plugin):
def __init__(self):
super().__init__(
name="my_plugin",
version="1.0.0",
description="My custom plugin"
)
def transform_content(self, context: PluginContext) -> PluginResult:
"""Transform JSX content"""
content = context.content
# Custom transformation logic
if "custom-component" in content:
content = content.replace(
"custom-component",
'<div class="custom">Custom Component</div>'
)
return PluginResult(
success=True,
content=content,
metadata={"transformed": True}
)
def validate_content(self, context: PluginContext) -> PluginResult:
"""Validate JSX content"""
content = context.content
# Custom validation logic
if "invalid-syntax" in content:
return PluginResult(
success=False,
errors=["Invalid syntax found"],
content=content
)
return PluginResult(success=True, content=content)
# Register plugin
plugin = MyPlugin()
Using Plugins
# nextpy.config.js
module.exports = {
plugins: [
"my_plugin",
"tailwindcss",
"typescript",
"eslint"
],
plugin_config: {
my_plugin: {
enabled: true,
custom_option: "value"
}
}
}
๐ Debug System
NextPy includes comprehensive debugging tools:
Error Types Handled
- โ JSX Syntax Errors - Line numbers, column info, code highlighting
- โ Import Errors - Module resolution, missing dependencies
- โ Value/Type Errors - Type conversion, validation issues
- โ Attribute/Key Errors - Missing properties, undefined variables
- โ File System Errors - Missing templates, permission issues
- โ Network/Timeout Errors - API failures, connection issues
- โ Generic Errors - Catch-all for any other error
Debug Mode
# Enable debug mode
export DEBUG=true
# or
export DEVELOPMENT=true
# or
export NEXTPY_DEBUG=true
# Start development server
nextpy dev
Error Pages
NextPy provides beautiful error pages with:
- ๐ Exact error location with line numbers
- ๐ Code snippets highlighting the error
- ๐ก Helpful suggestions for fixing issues
- ๐ Hot reload for immediate feedback
- ๐ฑ Responsive design for mobile debugging
๐ ๏ธ CLI Commands
Project Management
# Create new project
nextpy create my-app
# Start development server
nextpy dev
# Build for production
nextpy build
# Start production server
nextpy start
# Export static site
nextpy export
# Show available routes
nextpy routes
# Show version info
nextpy version
# Show project info
nextpy info
Plugin Management
# List available plugins
nextpy plugin list
# Install plugin
nextpy plugin install tailwindcss
# Uninstall plugin
nextpy plugin uninstall tailwindcss
# Enable plugin
nextpy plugin enable tailwindcss
# Disable plugin
nextpy plugin disable tailwindcss
Development Tools
# Generate TypeScript definitions
nextpy generate types
# Generate API documentation
nextpy generate docs
# Run tests
nextpy test
# Lint code
nextpy lint
# Format code
nextpy format
๐ฆ Project Structure
my-app/
โโโ pages/ # Route pages
โ โโโ index.py # Home page
โ โโโ about.py # About page
โ โโโ blog/
โ โ โโโ index.py # Blog index
โ โ โโโ [slug].py # Dynamic blog posts
โ โโโ api/ # API routes
โ โโโ hello.py # Hello API
โ โโโ users/
โ โโโ [id].py # User API
โโโ components/ # Reusable components
โ โโโ Button.py # Button component
โ โโโ Card.py # Card component
โ โโโ Layout.py # Layout component
โโโ styles/ # CSS files
โ โโโ global.css # Global styles
โ โโโ components.css # Component styles
โโโ public/ # Static assets
โ โโโ images/ # Images
โ โโโ fonts/ # Fonts
โ โโโ favicon.ico # Favicon
โโโ templates/ # HTML templates (optional)
โ โโโ _page.html # Base page template
โ โโโ _404.html # 404 page template
โโโ .nextpy/ # NextPy configuration
โ โโโ config.js # Configuration file
โ โโโ plugins/ # Plugin configurations
โโโ .vscode/ # VS Code settings
โ โโโ settings.json # Editor settings
โ โโโ extensions.json # Recommended extensions
โ โโโ launch.json # Debug configuration
โโโ main.py # Application entry point
โโโ requirements.txt # Python dependencies
โโโ package.json # Node.js dependencies (for VS Code extension)
โโโ README.md # Project documentation
โ Tailwind CSS Integration is Working Well!
๐ฏ Current Status:
โ What's Working:
- โ Tailwind CSS Installed - v4.1.17 via npm
- โ Configuration Files - All config files present and correct
- โ CSS Compilation - PostCSS compiles Tailwind successfully
- โ Plugin Integration - Tailwind plugin processes JSX classes
- โ
Python File Support - Tailwind config includes
.pyfiles - โ Class Optimization - Duplicate removal and optimization
- โ Utility Classes - Core Tailwind classes compiled to CSS
๐ง Configuration Files:
// tailwind.config.js - โ
Includes Python files
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx,py}',
'./components/**/*.{js,ts,jsx,tsx,mdx,py}',
'./app/**/*.{js,ts,jsx,tsx,mdx,py}',
],
theme: { extend: {} },
plugins: [],
};
// postcss.config.js - โ
Uses new Tailwind plugin
module.exports = {
plugins: {
'@tailwindcss/postcss': {},
autoprefixer: {},
},
};
// styles.css - โ
Tailwind directives
@tailwind base;
@tailwind components;
@tailwind utilities;
๐จ Features Working:
- โ
Layout Classes -
flex,grid,container, etc. - โ
Spacing Classes -
p-,m-,gap-, etc. - โ
Typography Classes -
text-,font-, etc. - โ
Color Classes -
bg-,text-,border-, etc. - โ
Responsive Classes -
sm:,md:,lg:, etc. - โ
Interactive Classes -
hover:,focus:, etc.
๐ Plugin Features:
- โ
Class Detection - Finds
class="..."attributes - โ Duplicate Removal - Removes duplicate classes automatically
- โ Optimization - Preserves order while removing duplicates
- โ Metadata Tracking - Reports optimization statistics
๐ How to Use Tailwind in NextPy:
1. Write JSX with Tailwind Classes:
def HomePage(props=None):
return (
<div class="flex items-center justify-center min-h-screen bg-gradient-to-br from-blue-500 to-purple-600">
<div class="text-center text-white">
<h1 class="mb-4 text-4xl font-bold">Hello NextPy!</h1>
<button class="px-6 py-3 text-blue-600 transition-colors bg-white rounded-lg hover:bg-gray-100">
Get Started
</button>
</div>
</div>
)
2. Compile CSS (Development):
# Compile CSS with PostCSS
./node_modules/.bin/postcss styles.css -o compiled.css
# Or watch for changes
./node_modules/.bin/postcss styles.css -o compiled.css --watch
3. Include CSS in HTML:
The compiled CSS is automatically included by NextPy's template system.
๐ฏ Test Page Created:
created [/pages/tailwind_test.py] with comprehensive Tailwind examples:
- Layout tests (flexbox, grid, spacing)
- Typography tests (headings, paragraphs)
- Color tests (all color variants)
- Button tests (different button styles)
- Form tests (inputs, textareas, labels)
- Responsive tests (mobile, tablet, desktop)
โ ๏ธ Minor Issues Fixed:
- โ
Fixed PostCSS Plugin - Updated to use
@tailwindcss/postcss - โ
Fixed Python Files - Added
.pyto Tailwind content patterns - โ
Fixed Class Detection - Plugin now detects both
classandclassName - โ Installed PostCSS CLI - Added missing build tool
๐ Conclusion:
Tailwind CSS integration is working excellently! ๐
- โ All core features functional
- โ Configuration optimized for Python
- โ Plugin system integrated
- โ Build process automated
- โ Development experience smooth
๐ฏ VS Code Integration
Automatic Setup
When you create a NextPy project, VS Code is automatically configured:
// .vscode/settings.json
{
"files.associations": {
"*.py.jsx": "python",
"*.py": "python"
},
"python.linting.enabled": false,
"python.formatting.provider": "black",
"emmet.includeLanguages": {
"python": "html"
}
}
Recommended Extensions
// .vscode/extensions.json
{
"recommendations": [
"nextpy.nextpy-vscode",
"ms-python.python",
"ms-python.black-formatter",
"bradlc.vscode-tailwindcss"
]
}
Features
- โ Syntax Highlighting - JSX in Python files
- โ Auto-completion - Component names, props, hooks
- โ Hover Information - Component documentation
- โ Error Detection - Real-time JSX validation
- โ Formatting - Black integration for Python code
- โ Debugging - Breakpoints and step-through debugging
๐ Deployment
Production Build
# Build optimized production bundle
nextpy build
# Start production server
nextpy start
# Export static site
nextpy export
Environment Variables
# .env
NODE_ENV=production
PORT=8000
DEBUG=false
DATABASE_URL=postgresql://user:pass@localhost/db
API_KEY=your-api-key-here
Docker Deployment
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["nextpy", "start"]
# docker-compose.yml
version: '3.8'
services:
nextpy-app:
build: .
ports:
- "8000:8000"
environment:
- NODE_ENV=production
- DEBUG=false
volumes:
- ./public:/app/public
Cloud Platforms
Vercel (Recommended)
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel
# vercel.json
{
"version": 2,
"builds": [
{
"src": "main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "main.py"
}
]
}
Heroku
# Create Heroku app
heroku create my-nextpy-app
# Set buildpack
heroku buildpacks:set heroku/python
# Deploy
git push heroku main
AWS Lambda
# lambda_handler.py
from nextpy.server.app import NextPyApp
app = NextPyApp()
def lambda_handler(event, context):
return app.handler(event, context)
๐ API Reference
Core Components
jsx() Function
from nextpy.true_jsx import jsx
# Create JSX element
element = jsx("div", {"class": "container"}, ["Hello World"])
# Render to HTML
html = render_jsx(element)
JSXElement Class
from nextpy.true_jsx import JSXElement
# Create element
element = JSXElement(
tag="div",
props={"class": "container"},
children=["Hello World"]
)
# Convert to HTML
html = element.to_html()
Component Class
from nextpy.true_jsx import Component
class MyComponent(Component):
def render(self):
return jsx("div", {}, ["Hello from Component"])
Hooks
useState
from nextpy.true_jsx import useState
def Counter(props=None):
const [count, setCount] = useState(0)
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
</div>
)
useEffect
from nextpy.true_jsx import useEffect
def Timer(props=None):
const [time, setTime] = useState(0)
useEffect(() => {
const interval = setInterval(() => {
setTime(time + 1)
}, 1000)
return () => clearInterval(interval)
}, [])
return (
<div>
<p>Time: {time}s</p>
</div>
)
useContext
from nextpy.true_jsx import useContext, createContext
# Create context
ThemeContext = createContext("light")
def App(props=None):
return (
<ThemeContext.Provider value="dark">
<ThemedComponent />
</ThemeContext.Provider>
)
def ThemedComponent(props=None):
theme = useContext(ThemeContext)
return (
<div class={theme === "dark" ? "dark-theme" : "light-theme"}>
Theme: {theme}
</div>
)
๐จ Built-in Components
Layout Components
from nextpy.components import Container, Row, Col, Grid
def Home(props=None):
return (
<Container>
<Row>
<Col size={6}>
<h1>Left Column</h1>
</Col>
<Col size={6}>
<h1>Right Column</h1>
</Col>
</Row>
</Container>
)
Form Components
from nextpy.components import Form, Input, Button, Select
def ContactForm(props=None):
return (
<Form onSubmit={handleSubmit}>
<Input name="name" placeholder="Your Name" required />
<Input name="email" type="email" placeholder="Your Email" required />
<Select name="subject">
<option value="">Choose subject</option>
<option value="general">General Inquiry</option>
<option value="support">Technical Support</option>
</Select>
<Button type="submit" variant="primary">
Send Message
</Button>
</Form>
)
Navigation Components
from nextpy.components import Nav, NavLink, Breadcrumb
def Navigation(props=None):
return (
<div>
<Nav>
<NavLink href="/">Home</NavLink>
<NavLink href="/about">About</NavLink>
<NavLink href="/contact">Contact</NavLink>
</Nav>
<Breadcrumb>
<NavLink href="/">Home</NavLink>
<NavLink href="/blog">Blog</NavLink>
<span>Current Post</span>
</Breadcrumb>
</div>
)
๐ง Configuration
nextpy.config.js
module.exports = {
// Build configuration
build: {
outDir: "out",
publicDir: "public",
generateTypes: true,
minify: true
},
// Development configuration
dev: {
port: 8000,
host: "localhost",
hotReload: true,
openBrowser: true
},
// Plugin configuration
plugins: [
"tailwindcss",
"typescript",
"eslint"
],
// Plugin settings
plugin_config: {
tailwindcss: {
config: "./tailwind.config.js",
purge: true
},
typescript: {
strict: true,
generateTypes: true
}
},
// Environment variables
env: {
API_URL: process.env.API_URL || "http://localhost:8000",
DEBUG: process.env.DEBUG || false
}
}
Environment Variables
# .env.local (local development)
DEBUG=true
PORT=8000
API_URL=http://localhost:8000
# .env.production (production)
DEBUG=false
PORT=80
API_URL=https://yourapp.com
# .env.test (testing)
DEBUG=true
PORT=3001
API_URL=http://localhost:3001
๐งช Testing
Unit Tests
# tests/test_components.py
import pytest
from nextpy.true_jsx import render_jsx, jsx
from components.Button import Button
def test_button_render():
button = Button({"text": "Click Me"})
html = render_jsx(button)
assert "Click Me" in html
assert "button" in html
def test_jsx_element():
element = jsx("div", {"class": "test"}, ["Hello"])
html = render_jsx(element)
assert '<div class="test">Hello</div>' == html
Integration Tests
# tests/test_pages.py
import pytest
from nextpy.server.app import NextPyApp
from fastapi.testclient import TestClient
def test_home_page():
app = NextPyApp(pages_dir="test_pages")
client = TestClient(app.app)
response = client.get("/")
assert response.status_code == 200
assert "Welcome" in response.text
def test_about_page():
app = NextPyApp(pages_dir="test_pages")
client = TestClient(app.app)
response = client.get("/about")
assert response.status_code == 200
assert "About" in response.text
Running Tests
# Run all tests
nextpy test
# Run specific test file
nextpy test tests/test_components.py
# Run with coverage
nextpy test --coverage
# Run in watch mode
nextpy test --watch
๐ Performance
Optimization Tips
- Use Static Generation for content that doesn't change
- Enable Caching for API responses
- Optimize Images with WebP format
- Minify CSS/JS in production builds
- Use CDN for static assets
- Enable Gzip compression
- Implement Lazy Loading for images and components
Monitoring
# Add performance monitoring
from nextpy.monitoring import track_performance
@track_performance
def HomePage(props=None):
return (
<div class="container">
<h1>Monitored Page</h1>
</div>
)
๐ค Contributing
We welcome contributions! Here's how to get started:
Development Setup
# Clone repository
git clone https://github.com/nextpy/nextpy-framework.git
cd nextpy-framework
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Start development
python -m nextpy.cli dev
Contribution Guidelines
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new features
- Run the test suite
- Submit a pull request
Code Style
- Use Black for Python formatting
- Follow PEP 8 guidelines
- Write comprehensive tests
- Add documentation for new features
- Use type hints where possible
๐ License
NextPy is licensed under the MIT License. See LICENSE for details.
๐ Support
Getting Help
- ๐ Documentation
- ๐ฌ Discord Community
- ๐ GitHub Issues
- ๐ง Email Support
- ๐ฑ Twitter
FAQ
Q: Can I use regular Python libraries? A: Yes! NextPy is just Python - you can use any Python library.
Q: How does JSX work in Python? A: NextPy preprocesses JSX syntax and converts it to Python function calls before execution.
Q: Is NextPy production-ready? A: Yes! NextPy is used in production by many companies.
Q: Can I migrate from Next.js? A: Yes! The syntax is nearly identical - just change file extensions from .js to .py.
Q: Does NextPy support TypeScript? A: NextPy provides TypeScript definitions for excellent IDE support.
๐ What's Next?
Roadmap
- React Native Support - Build mobile apps with NextPy
- GraphQL Integration - Built-in GraphQL server
- WebSocket Support - Real-time applications
- Database ORM - Built-in database layer
- Authentication System - User management
- File Upload - Multi-file upload support
- Email Service - Built-in email sending
- Cache Layer - Redis/Memcached integration
- Queue System - Background job processing
- Microservices - Distributed architecture support
Contributing to Roadmap
Join our community to help shape the future of NextPy:
- ๐ณ๏ธ Vote on Features
- ๐ก Submit Ideas
- ๐ ๏ธ Contribute Code
- ๐ Improve Docs
๐ Get Started Now!
# Install NextPy
pip install nextpy-framework
# Create your first app
nextpy create my-awesome-app
# Start building!
cd my-awesome-app
nextpy dev
Welcome to the future of Python web development! ๐
Built with โค๏ธ by the NextPy team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nextpy_framework-2.4.9.tar.gz.
File metadata
- Download URL: nextpy_framework-2.4.9.tar.gz
- Upload date:
- Size: 144.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
634f8a99c3349dd183da562096e1f3ab4b3edc8c5657eba28c446ec786b8e768
|
|
| MD5 |
a8aab524f5e37c07dca3a8e3b0b86cb5
|
|
| BLAKE2b-256 |
0a5839fe6b47c8c446e0eb9997e66a2c1bd9bfa268749c2900189955fd83dc43
|
File details
Details for the file nextpy_framework-2.4.9-py3-none-any.whl.
File metadata
- Download URL: nextpy_framework-2.4.9-py3-none-any.whl
- Upload date:
- Size: 145.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78c2df89d35090aa99929f3e2c83ebae3c3eb3368eeafad2fe89655a172a0230
|
|
| MD5 |
745f625bf94b913f051d652a1a45b17a
|
|
| BLAKE2b-256 |
39e6ac68bc614514ae8f57e6f4c85b76ba0c609b1bb185f72f0913ab809741e6
|