Skip to main content

High-performance Python framework built directly on uvicorn with built-in database models, migrations, and background tasks. Django if it 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 if it 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):
    resource = "/posts"
    name = "posts"
    
    @API.endpoint("/", methods=["GET"])
    async def list_posts(self, scope, receive, send, **kwargs):
        posts = [{"id": 1, "title": "Hello World"}]
        return await self.response(posts)
    
    @API.endpoint("/", 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(apis=[
    PostAPI()  # resource = "/posts" defined in class
])

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
from neutronapi.base import API
from neutronapi.application import Application

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

class PingAPI(API):
    resource = "/ping"
    
    @API.endpoint("/", methods=["GET"])
    async def ping(self, scope, receive, send, **kwargs):
        return await self.response({"status": "ok"})

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

Database Models

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)

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


# 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.4.tar.gz (82.2 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.4-py3-none-any.whl (95.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: neutronapi-0.1.4.tar.gz
  • Upload date:
  • Size: 82.2 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.4.tar.gz
Algorithm Hash digest
SHA256 8cac152c388575d3afbf8a27b1e125bc0aac9c36b15bc3fdff7425586be9261b
MD5 ae6a8a801ebebcf697ddd30b33d403cc
BLAKE2b-256 8216dbaea8f4609acc17bbb0648989d527ac0d6fd705c041ed9977a8b143b34d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: neutronapi-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 95.4 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 14c8833bfabb66dd43a75d8ca55827f55a05c00ab4ac4d8a24971b81c9cb029e
MD5 7211654b60900db319c1eb4f9a3cb54d
BLAKE2b-256 926b7f6decd66525f9d9da9845c1b06b7551d49233c25cb3d904ea2d6e1b4fd2

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