An open API service indexing awesome lists of open source software.

https://github.com/nitrosh/nitro-cli

Build static sites with Python code instead of template engines. Live reload, incremental builds, deploy anywhere.
https://github.com/nitrosh/nitro-cli

build-tool cli deploy html incremental-build jamstack live-reload nitro python python3 ssg static-site-generator

Last synced: 30 days ago
JSON representation

Build static sites with Python code instead of template engines. Live reload, incremental builds, deploy anywhere.

Awesome Lists containing this project

README

          

# Nitro CLI

A static site generator that lets you build websites using Python and [nitro-ui](https://github.com/nitrosh/nitro-ui).

[![PyPI](https://img.shields.io/pypi/v/nitro-cli?color=green)](https://pypi.org/project/nitro-cli/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nitro-cli)](https://pypi.org/project/nitro-cli/)
[![PyPI - License](https://img.shields.io/pypi/l/nitro-cli)](https://pypi.org/project/nitro-cli/)
[![image](https://img.shields.io/github/actions/workflow/status/nitrosh/nitro-cli/test.yml?branch=main)](https://github.com/nitrosh/nitro-cli/actions?query=branch%3Amain)

## Installation

```bash
pip install nitro-cli
```

### AI Assistant Integration

Add Nitro CLI knowledge to your AI coding assistant:

```bash
npx skills add nitro-sh/nitro-cli
```

This enables AI assistants like Claude Code to understand Nitro CLI and generate correct nitro-ui code.

## Quick Start

```bash
nitro new my-site
cd my-site
nitro dev
```

Visit . Build for production with `nitro build`.

## Writing Pages

Pages are Python files in `src/pages/` that export a `render()` function:

```python
# src/pages/index.py
from nitro_ui import HTML, Head, Body, Title, Meta, H1
from nitro import Page

def render():
return Page(
title="Home",
content=HTML(
Head(
Meta(charset="UTF-8"),
Meta(name="viewport", content="width=device-width, initial-scale=1.0"),
Title("Home"),
),
Body(H1("Welcome!"))
)
)
```

Output paths mirror the file structure: `src/pages/about.py` → `build/about.html`

## Features

- **Python-Powered** - Write pages in Python with nitro-ui instead of template languages
- **Live Reload** - Development server with automatic browser refresh
- **Incremental Builds** - Only rebuild changed pages
- **Dynamic Routes** - Generate pages from data with `[slug].py` pattern
- **Draft Pages** - Mark pages as drafts to exclude from production builds
- **Environment Variables** - Auto-load `.env` files with `from nitro import env`
- **Image Optimization** - Responsive images with WebP/AVIF conversion
- **Islands Architecture** - Partial hydration for interactive components
- **Plugin System** - Extend the build lifecycle with nitro-dispatch hooks
- **One-Click Deploy** - Netlify, Vercel, or Cloudflare Pages

## Dynamic Routes

Generate multiple pages from data using `[param].py` naming:

```python
# src/pages/blog/[slug].py
from nitro import Page
from nitro_datastore import NitroDataStore

def get_paths():
data = NitroDataStore.from_file("src/data/posts.json")
return [{"slug": p.slug, "title": p.title} for p in data.posts]

def render(slug, title):
return Page(title=title, content=...)
```

## Commands

| Command | Description |
|--------------------|------------------------------------|
| `nitro new ` | Create new project |
| `nitro init` | Initialize Nitro in current dir |
| `nitro dev` | Start dev server with live reload |
| `nitro build` | Build for production |
| `nitro preview` | Preview production build |
| `nitro routes` | List all routes |
| `nitro check` | Validate site without building |
| `nitro export` | Export site as zip archive |
| `nitro clean` | Remove build artifacts |
| `nitro deploy` | Deploy to hosting platform |
| `nitro info` | Show project and environment info |

Run `nitro --help` for options.

## Configuration

```python
# nitro.config.py
from nitro import Config

config = Config(
site_name="My Site",
base_url="https://mysite.com",
renderer={"minify_html": True},
plugins=[],
)
```

## Ecosystem

- **[nitro-ui](https://github.com/nitrosh/nitro-ui)** - Build HTML with Python, not strings
- **[nitro-datastore](https://github.com/nitrosh/nitro-datastore)** - Schema-free JSON data store with dot notation access
- **[nitro-dispatch](https://github.com/nitrosh/nitro-dispatch)** - Framework-agnostic plugin system
- **[nitro-image](https://github.com/nitrosh/nitro-image)** - Fast, friendly image processing for the web
- **[nitro-validate](https://github.com/nitrosh/nitro-validate)** - Dependency-free data validation

## License

This project is licensed under the BSD 3-Clause License. See the [LICENSE](LICENSE) file for details.