Skip to main content

The ML API Framework - FastAPI for Machine Learning

Project description

๐Ÿš€ NeuralForge

The AI-Native ML API Framework

Deploy ML models to production in minutes, not weeks.

Python 3.10+ CI ML Tests Code Quality License Tests Coverage Code Quality Version


๐ŸŽฏ What is NeuralForge?

NeuralForge is the modern Python framework for deploying ML models to production.

Built specifically for ML Engineers and Data Scientists, NeuralForge provides everything you need to serve ML models at scale:

  • โœ… Model Registry - Version and manage all your models
  • โœ… A/B Testing - Safely roll out model improvements
  • โœ… Monitoring - Track predictions and detect drift
  • โœ… Auto-scaling - Handle traffic spikes automatically
  • โœ… Production-ready - Security, logging, metrics built-in

Why NeuralForge?

FastAPI is great for general APIs. NeuralForge is built specifically for ML.

Feature FastAPI NeuralForge
Model Versioning โŒ Manual โœ… Built-in
A/B Testing โŒ Manual โœ… Built-in
Drift Detection โŒ Manual โœ… Built-in
Batch Prediction โŒ Manual โœ… Built-in
GPU Management โŒ Manual โœ… Built-in
ML Monitoring โŒ Manual โœ… Built-in

๐Ÿš€ Quick Start

Installation

Basic Installation:

pip install neuralforge

With ML Optimization (PyTorch):

pip install neuralforge[pytorch]

Full Installation:

pip install neuralforge[all]

Note: PyTorch is optional. The core framework works perfectly without it. PyTorch is only needed for model quantization and GPU acceleration features. See docs/guides/OPTIONAL_DEPENDENCIES.md for details.

Your First ML API (5 minutes)

from neuralforge import NeuralForge
from pydantic import BaseModel

# Create app
app = NeuralForge()

# Define input/output
class PredictionInput(BaseModel):
    text: str

class PredictionOutput(BaseModel):
    sentiment: str
    confidence: float

# Create endpoint
@app.post("/predict")
async def predict(data: PredictionInput) -> PredictionOutput:
    # Your ML model here
    sentiment = "positive" if "good" in data.text.lower() else "negative"
    
    return PredictionOutput(
        sentiment=sentiment,
        confidence=0.95
    )

# Run
if __name__ == "__main__":
    app.run(port=8000)

Test it:

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "This is great!"}'

๐ŸŽจ Key Features

1. Model Registry & Versioning

Manage multiple model versions with ease:

from neuralforge.ml import ModelRegistry

registry = ModelRegistry()

# Register models
@registry.register(name="sentiment", version="1.0.0")
class SentimentModelV1:
    def predict(self, text: str):
        return {"sentiment": "positive", "confidence": 0.9}

@registry.register(name="sentiment", version="2.0.0")
class SentimentModelV2:
    def predict(self, text: str):
        # Improved model
        return {"sentiment": "positive", "confidence": 0.95}

# Load specific version
model = await registry.load("sentiment", version="1.0.0")

2. Built-in A/B Testing

Test model improvements safely:

from neuralforge.ml import ABTest

# Create A/B test
ab_test = ABTest(
    name="sentiment-v2-test",
    variants={
        "control": {"version": "1.0.0", "traffic": 0.7},
        "treatment": {"version": "2.0.0", "traffic": 0.3}
    }
)

@app.post("/predict")
@ab_test.route()
async def predict(data: Input):
    # Automatically selects variant
    model = await ab_test.get_model()
    return model.predict(data)

3. Prediction Monitoring

Track model performance in production:

from neuralforge.ml import PredictionMonitor

monitor = PredictionMonitor(
    model_name="sentiment",
    track_latency=True,
    alert_on_degradation=True
)

@app.post("/predict")
@monitor.track()
async def predict(data: Input):
    # Automatically logged and monitored
    return model.predict(data)

4. Production Features Built-in

Everything you need for production:

  • โœ… Authentication - API keys, JWT, OAuth2
  • โœ… Rate Limiting - Protect your API
  • โœ… CORS - Cross-origin requests
  • โœ… Logging - Structured logging with masking
  • โœ… Metrics - Prometheus-compatible
  • โœ… Health Checks - Liveness and readiness probes

๐Ÿ“š Examples

Sentiment Analysis

# See examples/ml_api/main.py
# Full working sentiment analysis API with:
# - User authentication
# - Prediction history
# - Analytics
# - Rate limiting

Text Generation with Streaming

from neuralforge import NeuralForge
from neuralforge.streaming import SSEResponse, TokenStreamBuilder

app = NeuralForge()

@app.stream("/generate")
async def generate(prompt: str):
    builder = TokenStreamBuilder()
    
    # Stream tokens as they're generated
    async for token in llm.generate(prompt):
        yield builder.add_token(token)
    
    yield builder.finish()

gRPC Server

from neuralforge.grpc import GRPCServer, GRPCServicer, grpc_method

# Enable gRPC alongside HTTP
grpc_server = app.enable_grpc(port=50051)

class InferenceService(GRPCServicer):
    @grpc_method(response_streaming=True)
    async def StreamPredict(self, request, context):
        async for token in model.generate(request.prompt):
            yield TokenResponse(token=token)

grpc_server.register_service(InferenceService)

Benchmarking

# Run latency benchmarks
neuralforge benchmark run --scenario latency

# Compare against FastAPI/BentoML
neuralforge benchmark compare --against fastapi,bentoml

# Generate HTML report
neuralforge benchmark report --format html --output report.html

OpenTelemetry Tracing

from neuralforge.observability import TracingManager, configure_structured_logging

# Configure tracing
tracer = TracingManager(service_name="ml-api")
tracer.configure(exporter="otlp", endpoint="localhost:4317")

# Structured JSON logging
configure_structured_logging(
    service_name="ml-api",
    format_type="json"
)

๐Ÿณ Docker Deployment

One-Command Deployment

# Copy environment template
cp env.template .env

# Start everything (API + PostgreSQL + Redis)
docker compose up -d

# Check health
curl http://localhost:8000/health

See docs/deployment/DOCKER_QUICKSTART.md for details.


๐Ÿ“š Documentation

Quick Start

Core Documentation

Deployment

Guides

Contributing

๐Ÿ“– Complete Documentation Index


๐Ÿ—๏ธ Architecture

NeuralForge
โ”œโ”€โ”€ Core Framework
โ”‚   โ”œโ”€โ”€ Async Routing (FastAPI-like)
โ”‚   โ”œโ”€โ”€ Dependency Injection
โ”‚   โ”œโ”€โ”€ Database Integration (SQLAlchemy)
โ”‚   โ””โ”€โ”€ Middleware Stack
โ”‚
โ”œโ”€โ”€ ML Features (v0.8+)
โ”‚   โ”œโ”€โ”€ Model Registry
โ”‚   โ”œโ”€โ”€ A/B Testing
โ”‚   โ”œโ”€โ”€ Prediction Monitoring
โ”‚   โ””โ”€โ”€ Drift Detection
โ”‚
โ””โ”€โ”€ Production Features
    โ”œโ”€โ”€ Authentication & Authorization
    โ”œโ”€โ”€ Rate Limiting
    โ”œโ”€โ”€ Logging & Metrics
    โ””โ”€โ”€ Docker Deployment

๐Ÿงช Development

Setup

git clone https://github.com/rockstream/neuralforge.git
cd neuralforge

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt

# Run tests
pytest

Running Tests

# All tests
pytest

# With coverage
pytest --cov=neuralforge --cov-report=html

# Specific test
pytest tests/test_routing.py -v

Current Status: โœ… 117/117 tests passing


๐Ÿ—บ๏ธ Roadmap

โœ… v0.5 (Current) - Core Framework

  • Async routing with validation
  • Dependency injection
  • Database integration (SQLAlchemy)
  • Middleware (CORS, Security, Logging, Rate Limiting)
  • Docker deployment
  • 117 tests passing

๐Ÿ”„ v0.8 (6 weeks) - ML Essentials

  • Model Registry & Versioning
  • A/B Testing Framework
  • Prediction Monitoring
  • 3+ ML Examples

๐ŸŽฏ v1.0 (12 weeks) - Production ML Framework

  • Drift Detection
  • Model Optimization
  • GPU Support
  • Auto-scaling
  • Enterprise Features

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Areas we need help:

  • ๐Ÿ› Bug fixes
  • ๐Ÿ“ Documentation
  • ๐ŸŽจ ML examples
  • ๐Ÿ”Œ ML tool integrations
  • โšก Performance optimization

๐Ÿ“Š Comparison

NeuralForge vs FastAPI

Use FastAPI when:

  • Building general-purpose APIs
  • Need maximum flexibility
  • Not ML-specific

Use NeuralForge when:

  • Deploying ML models
  • Need model versioning
  • Want A/B testing built-in
  • Need drift detection
  • ML-specific features matter

NeuralForge vs BentoML

NeuralForge:

  • โœ… General-purpose + ML-specific
  • โœ… FastAPI-like developer experience
  • โœ… More flexible

BentoML:

  • โœ… ML-only focus
  • โœ… More opinionated
  • โœ… Mature ecosystem

๐Ÿš€ Enterprise Agent System

CI Code Quality

Production-ready code quality and security analysis powered by NeuralForge Enterprise Agents.

๐ŸŽฏ Features

  • Automated Quality Checks: Enterprise-grade code analysis on every PR
  • Security Scanning: SAST, dependency scanning, and secret detection
  • CI/CD Integration: GitHub Actions workflows with automated reporting
  • Metrics & Monitoring: Prometheus-compatible metrics collection

๐Ÿ“Š Current Status

  • Enterprise Coverage: 75% (Code Quality + Security + Observability + Integration)
  • Test Coverage: 71% (View Report)
  • Security Scans: Automated via Security Agent v2

๐Ÿ“š Documentation

๐Ÿ”ง Quick Start

# Run quality analysis
python .agent/cli.py analyze --quick

# Run security scan
python .agent/cli.py security

# View metrics
python .agent/cli.py metrics

Note: Replace YOUR_USERNAME in badge URLs with your GitHub username for live status badges.


๐Ÿ“„ License

MIT License - see LICENSE for details.


๐Ÿ™ Acknowledgments


๐Ÿ“ž Support


Built with โค๏ธ for ML Engineers

Get Started โ€ข Documentation โ€ข Examples

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

nforge-1.1.0.tar.gz (182.0 kB view details)

Uploaded Source

Built Distribution

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

nforge-1.1.0-py3-none-any.whl (213.0 kB view details)

Uploaded Python 3

File details

Details for the file nforge-1.1.0.tar.gz.

File metadata

  • Download URL: nforge-1.1.0.tar.gz
  • Upload date:
  • Size: 182.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nforge-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bcab55bb0f25bdc3450a51b2d93fa5b0f88c58c3c07615c26c4a83de45f46119
MD5 20e589f4eafde3154b54902d74e33fcc
BLAKE2b-256 62a6ad01a0a145f606df22d8ec6f35b330bb54edcd03a8aad39e0d0958e21e0a

See more details on using hashes here.

File details

Details for the file nforge-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: nforge-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 213.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nforge-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15473c8145aa1688062af497416d93129fba2e9c9cdb1af4e2e6d81ac9221c33
MD5 65903c6cff0848c489cd79723448b46a
BLAKE2b-256 f01902a838bb208b72e439bb52656d53b5221f95136294de487d0b548f50d60f

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