Skip to main content

Navigator: a batteries-included Web Framework based on aiohttp

Project description

โšก Navigator Framework

PyPI version Python License Downloads

A batteries-included async web framework built on aiohttp ๐Ÿš€

Navigator is a next-generation Python framework designed for building high-performance asynchronous APIs and web applications. Built on top of aiohttp and asyncio, it provides enterprise-grade features out of the box with a focus on developer productivity and application scalability.

โœจ Key Features

  • โšก Lightning Fast: Built on aiohttp + uvloop for maximum performance
  • ๐Ÿ”‹ Batteries Included: Authentication, WebSockets, templates, database connections, and more
  • ๐Ÿ—๏ธ Django-style Apps: Organize code with modular, reusable application components
  • ๐ŸŒ Multi-tenant Ready: Built-in sub-domain support for SaaS applications
  • ๐Ÿ”ง Centralized Config: Unified configuration management with NavConfig
  • ๐Ÿ”Œ Auto-Connections: Automatic database connection handling with AsyncDB
  • ๐Ÿ“ Class-based Views: Powerful CRUD operations with ModelViews
  • ๐ŸŽฏ Extensible: Plugin architecture for adding custom features

๐Ÿš€ Quick Start

Installation

# Using uv (recommended)
uv add navigator-api[uvloop,locale]

# Using pip
pip install navigator-api[uvloop,locale]

Create Your First App

# Create a new Navigator project
nav init

# Create an application
nav app create myapp

# Run the development server
nav run --debug --reload

Hello Navigator

# app.py
import asyncio
import uvloop
from navigator import Application
from aiohttp import web

async def hello(request):
    return web.Response(text="Hello Navigator! ๐Ÿš€")

async def main():
    # Set uvloop as the event loop policy
    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    # Create Navigator application
    app = Application(enable_jinja2=True)

    # Add routes
    app.router.add_get('/', hello)

    # Enable WebSocket support
    app.add_websockets()

    # Setup and run
    return app.setup()

if __name__ == '__main__':
    asyncio.run(main())

๐Ÿ—๏ธ Architecture

Class-based Views

Navigator provides powerful class-based views for building APIs:

from navigator.views import BaseView, ModelView
from aiohttp import web
from datamodel import BaseModel

class UserView(BaseView):
    async def get(self):
        return web.json_response({"users": []})

    async def post(self):
        data = await self.request.json()
        # Process user creation
        return web.json_response({"status": "created"})

# Model-based CRUD operations
class User(BaseModel):
    name: str
    email: str
    age: int

class UserModelView(ModelView):
    model = User
    path = '/api/users'

    # Automatic CRUD operations:
    # GET /api/users - List all users
    # GET /api/users/{id} - Get specific user
    # POST /api/users - Create user
    # PUT /api/users/{id} - Update user
    # DELETE /api/users/{id} - Delete user

Centralized Configuration

Navigator uses NavConfig for unified configuration management:

# settings/settings.py
from navconfig import config

# Database configuration
DATABASE_URL = config.get('DATABASE_URL', 'postgresql://user:pass@localhost/db')

# Cache configuration
REDIS_URL = config.get('REDIS_URL', 'redis://localhost:6379')

# App configuration
DEBUG = config.getboolean('DEBUG', False)
SECRET_KEY = config.get('SECRET_KEY', required=True)

# Multiple environment support
ENV = config.get('ENV', 'development')  # development, staging, production

Django-style Applications

Organize your code with modular applications:

myproject/
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ users/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ views.py
โ”‚   โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ”‚   โ”œโ”€โ”€ urls.py
โ”‚   โ”‚   โ””โ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ products/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ views.py
โ”‚       โ””โ”€โ”€ models.py
โ”œโ”€โ”€ settings/
โ”‚   โ””โ”€โ”€ settings.py
โ””โ”€โ”€ main.py
# apps/users/__init__.py
from navigator.applications import AppConfig

class UsersConfig(AppConfig):
    name = 'users'
    path = '/api/users'

    def ready(self):
        # App initialization code
        pass

Database Integration

Navigator integrates seamlessly with AsyncDB for database operations:

from navigator.views import ModelView
from asyncdb.models import Model

# Define your model
class User(Model):
    name: str
    email: str
    created_at: datetime

    class Meta:
        name = 'users'
        schema = 'public'

# Create CRUD API automatically
class UserAPI(ModelView):
    model = User
    path = '/api/users'

    # Optional: Add custom validation
    async def validate_payload(self, data):
        if 'email' not in data:
            raise ValueError("Email is required")
        return data

    # Optional: Add custom callbacks
    async def _post_callback(self, response, model):
        # Send welcome email, log activity, etc.
        pass

WebSocket Support

Real-time features with built-in WebSocket support:

from navigator import Application
from navigator.services.ws import WebSocketHandler

class ChatHandler(WebSocketHandler):
    async def on_message(self, message):
        # Broadcast message to all connected clients
        await self.broadcast(message)

app = Application()
app.add_websockets()
app.router.add_websocket('/ws/chat', ChatHandler)

๐Ÿ”Œ Extensions

Navigator's extension system allows you to add powerful features:

Authentication Extension

# Install: pip install navigator-auth
from navigator_auth import AuthConfig

class MyApp(Application):
    def configure(self):
        # Add JWT authentication
        self.add_extension(AuthConfig, {
            'secret_key': 'your-secret-key',
            'algorithm': 'HS256',
            'token_expiration': 3600
        })

Admin Interface

# Coming soon: Django-style admin interface
from navigator.admin import admin_site
from .models import User, Product

admin_site.register(User)
admin_site.register(Product)

app.include_router(admin_site.router, prefix='/admin')

๐Ÿ› ๏ธ CLI Tools

Navigator includes powerful CLI tools for development:

# Project management
nav init                        # Create new project
nav app create myapp            # Create new application

# Development
nav run                       # Start development server
nav shell                     # Interactive shell

๐Ÿ“ฆ Available Extensions

Navigator supports various optional dependencies:

# Performance optimizations
navigator-api[uvloop]         # uvloop for better async performance

# Internationalization
navigator-api[locale]         # Babel for i18n support

# Caching
navigator-api[memcache]       # Memcached support

# Production deployment
navigator-api[gunicorn]       # Gunicorn WSGI server

# All features
navigator-api[all]            # Install all optional dependencies

๐Ÿš€ Deployment

AWS App Runner

Navigator includes built-in support for AWS App Runner deployment:

# apprunner.yaml
version: 1.0
runtime: python3
build:
  commands:
    build:
      - pip install -r requirements.txt
      - python setup.py build_ext --inplace
run:
  runtime-version: '3.11'
  command: 'nav run --port 8080'
  network:
    port: 8080
    env: PORT

Docker

FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
RUN python setup.py build_ext --inplace

EXPOSE 8000
CMD ["nav", "run", "--port", "8000"]

๐Ÿ“‹ Requirements

  • Python: 3.9+ (3.11+ recommended)
  • Dependencies:
    • aiohttp >= 3.10.0
    • asyncio (built-in)
    • uvloop >= 0.21.0 (optional, recommended)

๐Ÿงช Testing

# Install development dependencies
uv add --dev pytest pytest-asyncio coverage

# Run tests
pytest

# Run with coverage
pytest --cov=navigator tests/

๐Ÿ“š Documentation

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/phenobarbital/navigator.git
cd navigator

# Create development environment
uv venv --python 3.11 .venv
source .venv/bin/activate

# Install development dependencies
uv sync --dev

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

๐Ÿ“œ License

Navigator is licensed under the BSD 3-Clause License. See LICENSE for details.

๐Ÿ™ Credits

Navigator is built on top of these amazing projects:

  • aiohttp - Async HTTP client/server framework
  • asyncio - Asynchronous I/O framework
  • uvloop - Fast asyncio event loop
  • Jinja2 - Template engine
  • AsyncDB - Database connectivity
  • NavConfig - Configuration management

๐Ÿ”— Links


Made with โค๏ธ by the Navigator team. Built for the async future of web development.

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

navigator_api-2.14.8.tar.gz (666.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

navigator_api-2.14.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

navigator_api-2.14.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

navigator_api-2.14.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page