Professional core framework for trading applications
Project description
Tradata Core
Professional core framework designed for trading and market data applications.
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 usagefastapi_example.py- FastAPI integrationflask_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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run the test suite
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- GitHub Issues: Report bugs or request features
- Documentation: Comprehensive guides and examples
- Examples: Working code examples
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
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 tradata_core-0.2.3.tar.gz.
File metadata
- Download URL: tradata_core-0.2.3.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b510ec35051e79b50e082cb4dc91e06e163760998337fe58befadcef58462e28
|
|
| MD5 |
e63b2915379b5ed2ac9a56bb0aea748d
|
|
| BLAKE2b-256 |
b1b902cc9cd75b2987eb93a22a596fca637abaeede3bb7d2b895054705adbc33
|
File details
Details for the file tradata_core-0.2.3-py3-none-any.whl.
File metadata
- Download URL: tradata_core-0.2.3-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dcccfa42dec4db00ce185cbf85d3c55bb9354e9ebfd348bbff3f5815fb55b97
|
|
| MD5 |
e95dbe2ee9a3b059a1f236c7609a6914
|
|
| BLAKE2b-256 |
0e46af587b7e8bbd761176e7246df7571f1846c3a6f770330dcd40718a743ebe
|