nextpy 0.3.3
⚡The Pure Python Framework for Web Apps, Meticulously Optimized for 🤖AI agents🤖. World's first AMS🥇
License: Apache-2.0
Requires Python: >=3.8,<4.0
Keywords: web,framework

<div align="center">
<img src="https://raw.githubusercontent.com/dotagent-ai/assets/main/nextpy_logo_light_theme.svg#gh-light-mode-only" alt="Nextpy Logo" width="320px">
<img src="https://raw.githubusercontent.com/dotagent-ai/assets/main/nextpy_logo_dark_theme.svg#gh-dark-mode-only" alt="Nextpy Logo" width="320px">

<p align="center">
    <a href="docs/🌎/繁體中文/README.md">繁體中文</a>
    .
    <a href="docs/🌎/简体中文/README.md">简体中文 </a>
    .
    <a href="docs/🌎/Français/README.md">Français </a>
    ·
    <a href="docs/🌎/German/README.md">German</a>
    ·
    <a href="docs/🌎/Italiano/README.md">Italiano</a>
    ·
    <a href="docs/🌎/Português/README.md">Português</a>
    ·
    <a href="docs/🌎/Tamil/README.md">Tamil</a>
    ·
    <a href="docs/🌎/Ukrainian/README.md">Ukrainian</a>
    ·
    <a href="docs/🌎/русский/README.md">русский</a>
    ·
    <a href="docs/🌎/عربي/README.md">عربي</a>
    ·
    <a href="docs/🌎/Español/README.md">Español</a>
    ·
    <a href="docs/🌎/हिंदी/README.md">हिंदी</a>
    ·
    <a href="docs/🌎/Türkçe/README.md">Türkçe</a>
    ·
    <a href="docs/🌎/한국어/README.md">한국어</a>
    
  </p>
<br>

<a href="https://discord.gg/asTZktHrcH" target="blank">
<img alt="Discord" src="https://img.shields.io/discord/1111984809821089883?style=for-the-badge&logo=discord&logoColor=white&label=Live%20Support%20%26%20Coding%20Bots%20on%20Discord&labelColor=%23684DFF&link=https%3A%2F%2Fdiscord.gg%2FasTZktHrcH">

</a>

![-----------------------------------------------------](https://res.cloudinary.com/dzznkbdrb/image/upload/v1694798498/divider_1_rej288.gif)

<h3><i>Streamlit's simplicity (but 4-10x faster) + FastAPI's full power + (Pydantic & SQL Alchemy)'s robustness</i></h3>
   

```diff
+ 🤖 Searching for 'OpenAMS' or 'OpenAgent'? They're now seamlessly integrated into Nextpy. +
```

</div>

## 🤩 Nextpy : Fast, Pure Pythonic Web Apps

Build any web app —effortlessly and quickly ⚡. It simplifies Pythonic development for everything from backends to frontends (yes, visually 🦚stunning frontends in Python!), AI integrations, APIs, and beyond—empowering both humans and AI agents.

Nextpy is designed to solve compatibility issues and improve code generation. It is built on our insight🔍 that the choice of underlying frameworks significantly affects the efficiency of AI code generation, regardless of other factors such as LLMs, prompts, or fine-tuning methods.

- ⏰ **What You Can Build in 1 hour:** Beautiful portfolios, dashboards, portals, data apps, internal tools, APIs etc.

- 📚 ***& The best part? Transferable Knowledge:*** Building with nextpy `progressively` teaches you framework-agnostic fundamentals and the best python libraries- FastAPI, Pydantic, SQLModel, Pandas, Jinja2, SQLAlchemy, etc.

- ⚡ **4-10x faster than Streamlit:** Our compiled app achieves a staggering 4-10x performance leap over Streamlit. See the difference for yourself at [nextpy.org](https://nextpy.org), boasting a PageSpeed score of 99/100
![image](https://res.cloudinary.com/doojikdqd/image/upload/v1704975583/github_nextpy/file_2024-01-11_11.30.21_dqfcx3.png)


![-----------------------------------------------------](https://res.cloudinary.com/dzznkbdrb/image/upload/v1694798498/divider_1_rej288.gif)

## 💡 Key Features

### Simplifying App Development:🧩
- **🐍 Unleash Python's Full Potential** - Eliminate complexities and build everything—frontend and backend—in Python, seamlessly integrating any Python library.

- **🎨 Rich UI Library** - Over 100 fully customizable built-in components for rapid UI development.

- **⚛️ Tap into React's Power with Pythonic Wrappers** - Harness the vast React ecosystem directly within Python, utilizing any React library **_without JavaScript knowledge._**

- **🚀 Built-in Performance Optimizations** - Deliver exceptional user experiences with automatic image, font, and script optimizations for lightning-fast loading speeds and responsiveness. See the difference for yourself at [nextpy.org](https://nextpy.org).

- **👁️‍🗨️ Accessibility Out of the Box** - Achieving accessibility can be complex. We've selected the best UI React components, like Radix, to ensure accessibility is a standard feature, not an afterthought.

![image](https://res.cloudinary.com/doojikdqd/image/upload/v1704936923/github_nextpy/accessible-nextpy_ij7lqu.gif)


### Better AI Generations: ‍🤖

- **🧠 More Effective Than Chaining or Prompt Engineering** - Next.py aligns with LLM processing patterns, enabling precise output control and optimal model utilization.

- **💡 Optimized for Code Generation** - Regardless of the LLMs, prompts, or fine-tuning used, the underlying app framework significantly impacts the efficiency of code generation. Next.py's architecture is specifically engineered to maximize efficiency.

- **💾 Session State with LLM** - Efficiently maintain state with LLMs, leveraging KV caches to convert multiple output tokens into prompt token batches. This approach reduces redundant generations, accelerating the handling of lengthy and intricate prompts. **_(only for open-source models)_**

- **🧪 Detect Syntax Errors**: Test LLM-generated code, identifying and correcting LLM hallucinations, invalid Nextpy methods, and automatically generating prompts for seamless fixes.

### Developer-First: ❤️

- **📘 Transferable Knowledge** - Learning Next.py teaches you framework-agnostic fundamentals and the best Python libraries, improving your python development expertise and enabling you to excel across any framework.

- **🛠️ Extensible** - If you know how to do something in Python or plain English, you can integrate it with nextpy.

![-----------------------------------------------------](https://res.cloudinary.com/dzznkbdrb/image/upload/v1694798498/divider_1_rej288.gif)

## 🚀 Quick Start (3 mins)

[![Build a python webapp in 3 minutes](https://github.com/anubrag/nextpy/assets/25473195/c41ea5b7-d270-451a-a0d0-8308ff9dbfdc)](https://www.youtube.com/watch?v=5Ex-c9wwiYE)


**1. Installing Nextpy**

Open your terminal and prepare for an adventure of a lifetime!

```bash
pip install nextpy
```

**(Remember, Python 3.7 or later is required.)**

**2. Initializing Your App**

Navigate to the desired directory for your project in the terminal. Use the `nextpy init` command to initialize a template app in your new directory.

```bash
nextpy init
```

**3. Choose your template:**

For now, just press enter to automatically default to the blank template.
```md
    Blank Template: A simple single page template
    Base Template: A multi-page app with a sidebar
```

**4. Running the App**

In the same directory where you previously ran nextpy init, enter the following command:

```bash
nextpy run
```

**5. View the App:**

Check out your app by visiting [http://localhost:3000](http://localhost:3000)

> [!NOTE]
> Your application is now fully functional. To view the frontend, navigate to `localhost:3000`. The backend server is accessible at `localhost:8000`.
> While it's unlikely you'll ever directly interact with it, the backend API documentation can be found at `localhost:8000/docs`, and the openapi.json file is located at `localhost:8000/openapi.json`.


## 🎨 Start with a template!

We speedup your development with a [ever growing list of community templates](https://github.com/dot-agent/nextpy/tree/main/app-examples). Some examples:

<table border="0">
  <tr>
    <td>
      <a target="_blank" href="https://nextpy.org/">
        <img src="https://res.cloudinary.com/doojikdqd/image/upload/v1703429508/github_nextpy/glide_datagrid_2x_fdxoyy.png" style="max-height:150px; width:auto; display:block;">
      </a>
    </td>
    <td>
      <a target="_blank" href="https://nextpy.org/">
        <img src="https://res.cloudinary.com/doojikdqd/image/upload/v1703429508/github_nextpy/portfolio_2x_y4lzet.png" style="max-height:150px; width:auto; display:block;">
      </a>
    </td>
     <td>
      <a target="_blank" href="https://nextpy.org/">
        <img src="https://res.cloudinary.com/doojikdqd/image/upload/v1703429509/github_nextpy/chart_2x_eh0q9x.png" style="max-height:150px; width:auto; display:block;">
      </a>
    </td>
     <td>
      <a target="_blank" href="https://nextpy.org/">
        <img src="https://res.cloudinary.com/doojikdqd/image/upload/v1703429509/github_nextpy/chat_app_2x_cmsaht.png" style="max-height:150px; width:auto; display:block;">
      </a>
    </td>
     <td>
      <a target="_blank" href="https://nextpy.org/">
        <img src="https://res.cloudinary.com/doojikdqd/image/upload/v1703429509/github_nextpy/crud_2x_bcxiyp.png" style="max-height:150px; width:auto; display:block;">
      </a>
    </td>
     <td>
      <a target="_blank" href="https://nextpy.org/">
        <img src="https://res.cloudinary.com/doojikdqd/image/upload/v1703429508/github_nextpy/login_2x_hgjpo2.png" style="max-height:150px; width:auto; display:block;">
      </a>
    </td>
  </tr>
  <tr>
    <td>Powerful tables</td>
    <td>Portfolio Sites</td>
    <td>Interactive Charts</td>
    <td>AI chat</td>
    <td>Crud Apps</td>
    <td>Onboarding</td>
  </tr>
</table>

### Setting Up the Template
1. Copy the template files to your local folder.
2. Install necessary dependencies with **`pip install -r requirements.txt`**.
3. Initialize your app by running **`nextpy init`**.
4. Launch the app with **`nextpy run`** to see it in action. To check the site visit `localhost:3000`


# ➖ or ➖ 
---

### 🤣 Building a Joke Generator App (5 mins)

Edit `myapp/myapp.py` to create your app.

#### 1. Import Libraries

```python
import nextpy as xt
import pyjokes
```

Start by importing `nextpy` for development and `pyjokes` for random jokes.

#### 2. Set Up the App State

```python
class State(xt.State):
    joke: str = "Click the button to get a joke!"

    def generate_joke(self):
        self.joke = pyjokes.get_joke()
```

Create a `State` class with a `joke` variable. Use `generate_joke` to fetch new jokes.

#### 3. Design the Main Page

```python
def index():
    layout = xt.vstack(
        xt.text(State.joke, font_size="2em"),
        xt.button("Generate Joke", on_click=State.generate_joke),
    )
    return layout
```

The `index` function arranges a joke display and a button. `vstack` is used to stack components vertically, while `hstack` is used to stack components horizontally.

#### 4. Optional Styling
```md
def index():
    layout = xt.vstack(
        xt.text(State.joke, font_size="2em"),
        xt.button("Generate Joke", on_click=State.generate_joke),

        spacing="1em",
        align_items="center",
        justify_content="center",
        height="100vh",
   )
    return layout
```
The `spacing` attribute adds space between the `text` and `button` elements, while `align_items` and `justify_content` ensure that these elements are centered. The stack's `height` is set to 100% of the Viewport Height (`100vh`), which allows the vertical stack to fill the entire height of your screen.

#### 5. Setup the app

```python
app = xt.App()
app.add_page(index)

```

Set up the app, add the main page. To view the frontend, navigate to `localhost:3000`. 


![-----------------------------------------------------](https://res.cloudinary.com/dzznkbdrb/image/upload/v1694798498/divider_1_rej288.gif)


## 🛣️ Project Roadmap

**🌟 Upcoming Features**

1. **Frontend Magic Components**
   - 🪄 **PDF Resume to Personal Site**: Create a "magic component" that converts PDF resumes into customizable, full-stack personal websites.

2. **Backend Modules**
   - 🔐 **User Authentication and Email Integration**: Add modules for robust login functionality and email subscription.
   - 🛒 **Modules for Blogging and E-commerce**: Add backend modules to facilitate blog management and e-commerce webapps.

3. **Build and Performance Optimization**
   - 🔧 **Compiler Enhancement with Rust or mojo**: Transitioning our existing compiler to Rust or mojo to achieve faster performance.

4. **Generative AI**
   - 🐍 **Nextpy LLM**: Build the best Python LLM.
   - 💬 **End-User Copilot Feature**: A chat-based copilot for app users that lets them interact with your product and do things by text. We have all the modules ready for this, we just need to simplify the abstraction. Just set `copilot = True` in xtconfig and you’re should be good to go.

## 🤗 Get Involved

**We welcome contributors of all skill levels! 🤝**

Want to make a difference? Start by forking our repository and sending in your pull requests. We're excited to welcome you to our community. Together, we'll craft something truly remarkable! ✨

![-----------------------------------------------------](https://res.cloudinary.com/dzznkbdrb/image/upload/v1694798498/divider_1_rej288.gif)


## Why another framework?
In our quest to create apps that write themselves, we delved deep into a labyrinth of coding tools, frameworks, and libraries. Our experiments spanned all major large language models (LLMs), thousands of prompts, and every major web development framework, from React to Streamlit.

Insight
> [!TIP]
> We found that the choice of the foundational app framework significantly influences code generation efficiency, irrespective of the LLMs, prompts, or fine-tuning methods.

Initially, reflex's flexibility seemed promising, aligning with several of our requirements. However, as we experimented with different web apps, crucial feature gaps emerged. Bridging these gaps necessitated extensive "glue code," which dramatically slowed down development.

For months, we resisted the urge to reinvent the wheel and tried to assemble different tools to bring our vision to life. Instead of creating a framework from scratch, we aimed to create an opinionated app starter kit by selectively incorporating the best features from top frameworks. Although we still view this project as a **full stack app starter kit** rather than a framework, the distinction is becoming somewhat blurred as we have developed several custom modules and made specific design decisions.

This novel framework merges the simplicity of Streamlit with the speed and adaptability of Next.js. For the backend, we opted for FastAPI for its simplicity, coupled with Pydantic for robust type-checking. Our frontend was crafted using a tailored version of the Reflex library, incorporating new components. Currently, we are in the process of overhauling the core Python-to-JavaScript compiler to optimize speed. Additionally, we embraced SQLModel & SQLAlchemy for database connectivity. Furthermore, we have developed selected features specifically for generative AI. We have created a JSON-based database that uses JSON as the data storage medium, while also providing SQL-like capabilities.

**Our mission?** Make Next.py the most efficient app framework, for humans and AI alike!

Want to know more? Check out our manifesto! https://nextpy.org/manifesto/

## 🙏 Thanks


Nextpy Framework is a state-of-the-art app development framerwork optimized for AI-based code generation, built on the open-source community’s spirit of cooperation. It integrates key components from landmark projects like Guidance, Llama-Index, FastAPI-Mail, LangChain, ReactPy, Reflex, Chakra, Radix, Numpy and Next.js, while also drawing insights from the React and Rust ecosystems. This fusion ideas has been pivotal in shaping Nextpy into a framework that's not just AI-friendly but also a trailblazer in generative web development tools.

We are deeply grateful to the open-source creators, contributors, and maintainers whose work has provided the basis for Nextpy. Your commitment to innovation and openness has been vital for shaping this framework. Your contributions have not only enhanced Nextpy but are also advancing the new era of AI-powered software development. Thank you for being the catalysts and enablers of this transformational journey.