Skip to main content

High-performance Python framework built directly on uvicorn with built-in database models, migrations, and background tasks. Django that was built async-first.

Project description

NeutronAPI

High-performance Python framework built directly on uvicorn with built-in database models, migrations, and background tasks. If you want Django that was built async-first, this is for you.

Batteries included async API framework with command-line management.

Installation

pip install neutronapi

Quick Start

# 1. Create project
neutronapi startproject blog
cd blog

# 2. Create an app
python manage.py startapp posts

# 3. Start server  
python manage.py start               # Dev mode (auto-reload)

# 4. Test
python manage.py test

Getting Started Tutorial

1. Create Project

neutronapi startproject blog
cd blog

2. Create App Module

python manage.py startapp posts

3. Configure in apps/settings.py

import os

# ASGI application entry point (required for server)
ENTRY = "apps.entry:app"  # module:variable format

# Database
DATABASES = {
    'default': {
        'ENGINE': 'aiosqlite',
        'NAME': 'db.sqlite3',
    }
}

4. Create API in apps/posts/api.py

from neutronapi.base import API

class PostAPI(API):
    name = "posts"
    
    @API.endpoint("/posts", methods=["GET"])
    async def list_posts(self, scope, receive, send, **kwargs):
        posts = [{"id": 1, "title": "Hello World"}]
        return await self.response(posts)
    
    @API.endpoint("/posts", methods=["POST"])
    async def create_post(self, scope, receive, send, **kwargs):
        # Get request data from scope["body"]
        return await self.response({"id": 2, "title": "New Post"})

5. Register API in apps/entry.py

from neutronapi.application import Application
from apps.posts.api import PostAPI

app = Application({
    "posts": PostAPI()
})

6. Start Server

python manage.py start
# Visit: http://127.0.0.1:8000/posts

Project Structure

myproject/
├── manage.py           # Management commands
├── apps/
│   ├── __init__.py
│   ├── settings.py     # Configuration 
│   └── entry.py        # ASGI application
└── db.sqlite3          # Database

Background Tasks

from neutronapi.background import Task, TaskFrequency

class CleanupTask(Task):
    name = "cleanup"
    frequency = TaskFrequency.MINUTELY
    
    async def run(self, **kwargs):
        print("Cleaning up logs...")

# Add to application
app = Application(
    apis={"ping": PingAPI()},
    tasks={"cleanup": CleanupTask()}
)

## Database Models

```python
from neutronapi.db.models import Model
from neutronapi.db.fields import CharField, IntegerField, DateTimeField

class User(Model):
    name = CharField(max_length=100)
    age = IntegerField()
    created_at = DateTimeField(auto_now_add=True)
    
    # Table name inferred from class name (user -> users)

Server Commands

# Development (auto-reload, localhost)
python manage.py start

# Production (multi-worker, optimized)  
python manage.py start --production

# Custom configuration
python manage.py start --host 0.0.0.0 --port 8080 --workers 4

Testing

# SQLite (default)
python manage.py test

# PostgreSQL (auto Docker bootstrap)
DATABASE_PROVIDER=asyncpg python manage.py test

# Specific tests
python manage.py test app.tests.test_models.TestUser.test_creation

Commands

python manage.py start              # Start server
python manage.py test               # Run tests  
python manage.py migrate            # Run migrations
python manage.py startapp posts     # Create new app

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neutronapi-0.1.0.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

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

neutronapi-0.1.0-py3-none-any.whl (86.5 kB view details)

Uploaded Python 3

File details

Details for the file neutronapi-0.1.0.tar.gz.

File metadata

  • Download URL: neutronapi-0.1.0.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for neutronapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 19a6cd530204b73a3711e75c0d4c3164177a725c5c4ca10933cffb543add94fa
MD5 a75d537a42c74981829ba9c5027f95a6
BLAKE2b-256 7b0772dcbc0f538c65516ebb1bb275b33491ca57fb8e8dea929f638790a986b1

See more details on using hashes here.

File details

Details for the file neutronapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: neutronapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 86.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for neutronapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89564d6d37b7b2d8cf21591a3732bb803730f1eb94cc56659049faa9def40c32
MD5 1247e3fbd7db45bd847d2b3e0e34f2f3
BLAKE2b-256 6751062fae7c2e1b2ed65f706090aaf73850838b3aaeaf347c90145d2f0ba48c

See more details on using hashes here.

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