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.
๐ฏ 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
- Quick Start Guide - Get started in 5 minutes
- Production Quickstart - Production-ready setup
Core Documentation
- Production Features - All production features explained
- Core Functionalities - Framework capabilities
- Code Structure - Project organization
- Code Quality - Quality standards and best practices
Deployment
- Docker Deployment - Complete Docker guide
- Docker Quickstart - Quick Docker setup
Guides
- Testing Examples - Testing patterns
- Optional Dependencies - ML framework options
Contributing
- Contributing Guide - How to contribute
- Changelog - Version history
๐ 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
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
- Deployment Guide - Production deployment instructions
- Quick Reference - Daily CLI commands
- Enterprise Agent Docs - Technical 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
- Inspired by FastAPI - Amazing DX
- Inspired by BentoML - ML serving patterns
- Built with Pydantic, SQLAlchemy, and Uvicorn
๐ Support
- Documentation: [Coming Soon]
- GitHub Issues: Report bugs
- Discord: Join community (Coming Soon)
- Email: support@neuralforge.dev
Built with โค๏ธ for ML Engineers
Get Started โข Documentation โข Examples
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcab55bb0f25bdc3450a51b2d93fa5b0f88c58c3c07615c26c4a83de45f46119
|
|
| MD5 |
20e589f4eafde3154b54902d74e33fcc
|
|
| BLAKE2b-256 |
62a6ad01a0a145f606df22d8ec6f35b330bb54edcd03a8aad39e0d0958e21e0a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15473c8145aa1688062af497416d93129fba2e9c9cdb1af4e2e6d81ac9221c33
|
|
| MD5 |
65903c6cff0848c489cd79723448b46a
|
|
| BLAKE2b-256 |
f01902a838bb208b72e439bb52656d53b5221f95136294de487d0b548f50d60f
|