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+ PyPI Downloads CI License Tests 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 nforge

With ML Optimization (PyTorch):

pip install nforge[pytorch]

Full Installation:

pip install nforge[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.1.tar.gz (181.9 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.1-py3-none-any.whl (213.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nforge-1.1.1.tar.gz
  • Upload date:
  • Size: 181.9 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.1.tar.gz
Algorithm Hash digest
SHA256 24f5e60c1054758098b471cb08f963747a0932ee90c066bf3e080b15d7f6aee2
MD5 eff6322941722c3a0b623b4c33c62f7a
BLAKE2b-256 b3cab8a98b59c7bc85b0410cd6c93354a047165091e14a6510dbf354f77efe1b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nforge-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8096a149bef7c10185dd98fd159f3270dd23448c0e1bcaae96b1287ab40ea26
MD5 813d7774a5a7be411dc08956bfdd9bfc
BLAKE2b-256 770bd1b6f27972ddcbd680dc928ddf5a2710a639c140422f68b6cd498a237be8

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