Skip to main content

Professional core framework for trading applications

Project description

Tradata Core

Professional core framework designed for trading and market data applications.

Python 3.8+ License: MIT PyPI version

Features

  • 🚀 FastAPI Middleware - Automatic request logging with trace IDs
  • 📊 Structured JSON Logging - Consistent, searchable log format
  • 🔗 Request Correlation - Track requests across microservices
  • High Performance - Async-first design with minimal overhead
  • 🎯 Trading-Specific - Specialized logging for financial applications
  • 🔧 Easy Configuration - Environment variables and programmatic setup
  • 🎭 Context Management - Automatic operation and step tracking
  • 🏷️ Decorators - One-liner logging for API endpoints

Quick Start

Installation

This is a private package accessible only to your GitHub organization.

Option 1: Automated Setup (Recommended)

# Download and run the setup script
curl -O https://raw.githubusercontent.com/your-org/tradata-core-py/main/setup_private_install.sh
chmod +x setup_private_install.sh
./setup_private_install.sh YOUR_GITHUB_TOKEN_HERE

Option 2: Manual Installation

# Install from private GitHub Packages
pip install tradata-core-py

# Or install directly from private repository
pip install git+https://YOUR_TOKEN@github.com/your-org/tradata-core-py.git

See Private Package Setup Guide for detailed instructions.

Basic Usage

from tradata_core import get_logger

logger = get_logger("my-service")
await logger.info("Service started", "Service", "Startup")

FastAPI Integration

from fastapi import FastAPI
from tradata_core import LoggingMiddleware

app = FastAPI()
app.add_middleware(LoggingMiddleware)

# Automatic request logging with trace IDs!

Why Tradata Logger?

For Trading Applications

  • Operation Tracking: Log business operations (e.g., "QuoteRetrieval", "TradeExecution")
  • Step Monitoring: Track specific steps within operations (e.g., "Validation", "API_Call")
  • Performance Metrics: Built-in timing and performance logging
  • Cache Operations: Specialized logging for cache hits/misses
  • Client Tracking: Monitor external API usage and performance

For Microservices

  • Trace ID Propagation: Follow requests across service boundaries
  • Request Correlation: Link related operations with unique identifiers
  • Structured Logging: Consistent JSON format for log aggregation
  • Middleware Integration: Framework-specific middleware for automatic logging

For Development Teams

  • Clean APIs: Decorators and context managers for minimal code
  • Comprehensive Coverage: Automatic logging of requests, errors, and performance
  • Flexible Configuration: Environment-based and programmatic configuration
  • Extensible Design: Easy to add custom formatters and handlers

Core Concepts

Operation and Step Tracking

Every log entry includes:

  • Operation: High-level business operation (e.g., "QuoteRetrieval")
  • Step: Specific step within the operation (e.g., "API_Call", "Validation")
await logger.info("Quote retrieved", "QuoteRetrieval", "API_Call", symbol="AAPL")

Context Variables

Automatic tracking of:

  • Trace ID: Unique identifier for request chains
  • Request ID: Unique identifier for individual requests
  • Client: External service being used

Structured Logging

All logs include structured data for easy searching and analysis:

{
  "timestamp": "2024-01-15T10:30:00Z",
  "level": "INFO",
  "message": "Quote retrieved successfully",
  "operation": "QuoteRetrieval",
  "step": "API_Call",
  "trace_id": "trace_12345",
  "request_id": "req_67890",
  "client": "alpaca_api",
  "symbol": "AAPL",
  "duration_ms": 150.5
}

Usage Examples

Basic Logging

from tradata_core import get_logger

logger = get_logger("quotes-service")

# Basic logging
await logger.info("Processing started", "DataProcessing", "Validation")
await logger.error("API call failed", "ExternalAPI", "Call", error="Connection timeout")

# Specialized logging
await logger.log_cache_operation("Cache_Get", True, "quote:AAPL", 5.0)
await logger.log_client_operation("API_Call", "alpaca_api", "get_quote", 150.0)

API Endpoint Logging

from tradata_core.utils.decorators import log_endpoint

@app.get("/quotes/{symbol}")
@log_endpoint("/quotes/{symbol}", "quote_retrieval", "quotes_service")
async def get_quote(symbol: str):
    # Automatic logging of request, processing, and response
    return {"symbol": symbol, "price": 150.00}

Context Management

from tradata_core.utils.context import logging_context

async with logging_context("data_processing", "batch_validation") as ctx:
    ctx.add_context(batch_size=1000, dataset="market_data")
    
    for item in data:
        # Process item
        pass
    
    # Automatic completion logging with duration

FastAPI Middleware

from tradata_core import LoggingMiddleware, PerformanceLoggingMiddleware

app = FastAPI()

# Basic logging middleware
app.add_middleware(LoggingMiddleware)

# Performance-focused middleware
app.add_middleware(PerformanceLoggingMiddleware)

Configuration

Environment Variables

LOG_LEVEL=INFO
LOG_FORMAT=json
LOG_INCLUDE_TRACE_ID=true
LOG_PERFORMANCE=true
LOG_CACHE_OPERATIONS=true

Programmatic Configuration

from tradata_core.config import LogConfig, HandlerConfig

config = LogConfig(
    level="DEBUG",
    format="console",
    handlers=[
        HandlerConfig(type="console", level="DEBUG"),
        HandlerConfig(type="file", filename="app.log", level="INFO")
    ]
)

Installation

From PyPI

pip install tradata-logger

From Source

git clone https://github.com/tradata/tradata-logger-py.git
cd tradata-logger-py
pip install -e .

Development Dependencies

pip install -e ".[dev]"

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=tradata_core

# Run specific test file
pytest tests/test_logger.py

Examples

See the examples/ directory for complete working examples:

  • basic_usage.py - Basic logger usage
  • fastapi_example.py - FastAPI integration
  • flask_example.py - Flask integration (placeholder)

Documentation

Comprehensive documentation is available in the docs/ directory:

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run the test suite
  6. Submit a pull request

License

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

Support

Roadmap

  • Flask middleware implementation
  • Additional log formatters
  • Cloud logging integrations
  • Performance dashboard
  • Log aggregation tools
  • More specialized logging methods

Acknowledgments

  • Built for the trading and financial technology community
  • Inspired by modern logging practices and observability needs
  • Designed with microservices and distributed systems in mind

Tradata Logger - Professional logging for professional applications.

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

tradata_core-0.2.6.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

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

tradata_core-0.2.6-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file tradata_core-0.2.6.tar.gz.

File metadata

  • Download URL: tradata_core-0.2.6.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tradata_core-0.2.6.tar.gz
Algorithm Hash digest
SHA256 ece5aaeeeea4523171518508e3e0dfeb56783a09fe00fe19c33f07d81cc5881b
MD5 c7ae8f698ab97ee07095d4710375cea4
BLAKE2b-256 42e5e9aa88a8476f3ba05da47a7341c40b44bf85d6d8dc99b33f7e2a5c29c6d2

See more details on using hashes here.

File details

Details for the file tradata_core-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: tradata_core-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tradata_core-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2e622ab21c2da41cbdba9fa6f38a0880fd3474eeffdb684c392043ed4ec793e6
MD5 082e762c0b66c3d5931d01e246fe624e
BLAKE2b-256 95040888bcec97b13ead0d7371565bb4e0ff67bb88689f7b42b938c768a2272d

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