Skip to main content

MGraph-AI__Service__Cache__Client

Project description

MGraph AI Service Cache Client

Current Release Python FastAPI AWS Lambda License CI Pipeline - DEV

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

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:

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

  1. 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)
  1. 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:

  1. Development Branch (dev)

    • Runs tests with LocalStack
    • Deploys to dev environment
    • Increments minor version
  2. Main Branch (main)

    • Runs comprehensive test suite
    • Deploys to QA environment
    • Increments major version
  3. 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

  1. Never commit secrets - Use environment variables
  2. Rotate API keys - Regular key rotation
  3. Use HTTPS - Always encrypt in transit
  4. Monitor access - Log and audit API usage

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


Created and maintained by The Cyber Boardroom team

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

mgraph_ai_service_cache_client-0.1.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

mgraph_ai_service_cache_client-0.1.2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file mgraph_ai_service_cache_client-0.1.2.tar.gz.

File metadata

File hashes

Hashes for mgraph_ai_service_cache_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9b70deba10a8b1df406444d4ef6581325f6491ce87015da9348091c71daf5158
MD5 27388b99da51e6fc124f2e944484d083
BLAKE2b-256 b09142d23d2dff058481faa9211ec9fd13d4abaa654e6ce2d153946d739c3b47

See more details on using hashes here.

File details

Details for the file mgraph_ai_service_cache_client-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mgraph_ai_service_cache_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b6658b8d862b36068fc85cbb59a1fbbab68dfa3d42456419ff38cd7d96d4e063
MD5 530452c766b46b348a949b2c3ababa42
BLAKE2b-256 1449ed64b9dcea54fa83b310824aef01ec5d0ee32d8115cc1085aa4dccc09849

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