MGraph-AI__Service__Cache__Client
Project description
MGraph AI Service Cache Client
A production-ready FastAPI microservice template for building MGraph-AI services. This template provides a complete scaffold with CI/CD pipeline, AWS Lambda deployment, and type-safe architecture.
๐ฏ Purpose
This repository serves as the base template for creating new MGraph-AI services. It includes:
- โ Complete FastAPI application structure
- โ Multi-stage CI/CD pipeline (dev, qa, prod)
- โ AWS Lambda deployment configuration
- โ Type-safe architecture using OSBot-Utils
- โ Comprehensive test coverage
- โ API key authentication
- โ Health check and monitoring endpoints
Note: This is a template repository. To create your own service, see Creating Services from Template.
๐ Creating a New Service
To create a new service from this template, see Creating Services from MGraph-AI__Service__Cache__Client.
๐ Features
- Type-Safe Architecture: Built on OSBot-Utils type safety framework
- Multi-Stage Deployment: Automated CI/CD pipeline for dev, QA, and production
- AWS Lambda Ready: Optimized for serverless deployment
- API Key Authentication: Secure access control
๐ Table of Contents
- Quick Start
- Installation
- API Documentation
- Configuration
- Development
- Testing
- Deployment
- Security
- Contributing
- License
๐ฏ Quick Start
Local Development
# Clone the repository
git clone https://github.com/the-cyber-boardroom/MGraph-AI__Service__Cache__Client.git
cd MGraph-AI__Service__Cache__Client
# Install dependencies
pip install -r requirements-test.txt
pip install -e .
# Set environment variables
export FAST_API__AUTH__API_KEY__NAME="x-api-key"
export FAST_API__AUTH__API_KEY__VALUE="your-secret-key"
# Run locally
./scripts/run-locally.sh
# or
uvicorn mgraph_ai_service_cache__client.fast_api.lambda_handler:app --reload --host 0.0.0.0 --port 10011
Basic Usage
import requests
# Set up authentication
headers = {"x-api-key": "your-secret-key"}
base_url = "http://localhost:10011"
# Check service health
response = requests.get(f"{base_url}/health", headers=headers)
print(response.json())
# Get service info
response = requests.get(f"{base_url}/info/version", headers=headers)
print(response.json())
๐ฆ Installation
Prerequisites
- Python 3.12+
- AWS CLI (for deployment)
- Docker (for LocalStack testing)
Using Poetry
# Install poetry if not already installed
pip install poetry
# Install dependencies
poetry install
# Activate virtual environment
poetry shell
Using pip
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements-test.txt
pip install -e .
๐ API Documentation
Interactive API Documentation
Once the service is running, access the interactive API documentation at:
- Swagger UI: http://localhost:10011/docs
- ReDoc: http://localhost:10011/redoc
Endpoints Overview
Health Endpoints
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Service health check |
/health/detailed |
GET | Detailed health status |
Information Endpoints
| Endpoint | Method | Description |
|---|---|---|
/info/version |
GET | Get service version |
/info/status |
GET | Get service status |
โ๏ธ Configuration
Environment Variables
| Variable | Description | Required | Default |
|---|---|---|---|
FAST_API__AUTH__API_KEY__NAME |
Header name for API key | Yes | - |
FAST_API__AUTH__API_KEY__VALUE |
API key value | Yes | - |
AWS_REGION |
AWS region (triggers Lambda mode) | No | - |
DEBUG |
Enable debug logging | No | false |
Configuration File
Create a .env file for local development:
FAST_API__AUTH__API_KEY__NAME=x-api-key
FAST_API__AUTH__API_KEY__VALUE=development-key-12345
๐ ๏ธ Development
Project Structure
mgraph_ai_service_cache__client/
โโโ fast_api/
โ โโโ lambda_handler.py # AWS Lambda entry point
โ โโโ Service__Fast_API.py # FastAPI application setup
โ โโโ routes/ # API endpoint definitions
โโโ service/
โ โโโ info/ # Service information
โโโ utils/
โ โโโ deploy/ # Deployment utilities
โ โโโ Version.py # Version management
โโโ config.py # Service configuration
Adding New Endpoints
- Create a new route class in
fast_api/routes/:
from osbot_fast_api.api.Fast_API_Routes import Fast_API_Routes
class Routes__MyFeature(Fast_API_Routes):
tag = 'my-feature'
def my_endpoint(self, param: str = "default"):
return {"result": param}
def setup_routes(self):
self.add_route_get(self.my_endpoint)
- Register in
Service__Fast_API:
def setup_routes(self):
# ... existing routes
self.add_routes(Routes__MyFeature)
๐งช Testing
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=mgraph_ai_service_cache__client
# Run specific test file
pytest tests/unit/fast_api/test_Service__Fast_API__client.py
# Run integration tests (requires LocalStack)
pytest tests/integration/
Test Structure
tests/
โโโ unit/ # Unit tests
โ โโโ fast_api/ # API tests
โ โโโ service/ # Service tests
โโโ deploy_aws/ # Deployment tests
๐ Deployment
AWS Lambda Deployment
The service includes automated deployment scripts for multiple environments:
# Deploy to development
pytest tests/deploy_aws/test_Deploy__Service__to__dev.py
# Deploy to QA
pytest tests/deploy_aws/test_Deploy__Service__to__qa.py
# Deploy to production (manual trigger)
# Use GitHub Actions workflow
CI/CD Pipeline
The project uses GitHub Actions for continuous deployment:
-
Development Branch (
dev)- Runs tests with LocalStack
- Deploys to dev environment
- Increments minor version
-
Main Branch (
main)- Runs comprehensive test suite
- Deploys to QA environment
- Increments major version
-
Production (manual)
- Requires manual workflow trigger
- Deploys to production environment
๐ Security
Authentication
API key authentication is required for all endpoints:
headers = {"x-api-key": "your-secret-key"}
Best Practices
- Never commit secrets - Use environment variables
- Rotate API keys - Regular key rotation
- Use HTTPS - Always encrypt in transit
- Monitor access - Log and audit API usage
๐ค Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Guidelines
- Write tests for new features
- Update documentation
- Follow existing code style
- Add type annotations
- Consider security implications
๐ Related Projects
- OSBot-Utils - Core utilities library
- OSBot-AWS - AWS integration layer
- OSBot-Fast-API - FastAPI utilities
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
๐ Acknowledgments
- Built with FastAPI
- Deployed on AWS Lambda
๐ Support
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
Created and maintained by The Cyber Boardroom team
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 mgraph_ai_service_cache_client-0.27.0.tar.gz.
File metadata
- Download URL: mgraph_ai_service_cache_client-0.27.0.tar.gz
- Upload date:
- Size: 53.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c2a463280ec250f12cc032779edecc754bb169668b4dc2a744bcd145c51289f
|
|
| MD5 |
d4de635cd46608f1416182fc5c1dd04a
|
|
| BLAKE2b-256 |
d7b011f95d1d647ebb59a07588a58ddba4215f13fd9372ea23c07acd9676a08b
|
File details
Details for the file mgraph_ai_service_cache_client-0.27.0-py3-none-any.whl.
File metadata
- Download URL: mgraph_ai_service_cache_client-0.27.0-py3-none-any.whl
- Upload date:
- Size: 112.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74bbb40cefb6d883253c63b4615586a31e67598c5b4b90d7f501c3e97616f3fc
|
|
| MD5 |
43a7b94ab671857821498a720dd9baf1
|
|
| BLAKE2b-256 |
6f3eb5a81a297b0f32b5fd12fda524afdfe52768bae658617090cfb36776c473
|