A Python library for processing AWS Application Load Balancer (ALB) logs.
- Parse access logs: Extract detailed request/response information
- Parse connection logs: Analyze TLS connection details
- Parse health check logs: Monitor target health status
- S3 integration: Read logs directly from S3 buckets (optional)
- Type-safe: Full type hints for better IDE support and code quality
- Well-tested: Comprehensive test suite with pytest
# Using uv (recommended)
uv pip install libalb
# Using pip
pip install libalb# Using uv
uv pip install "libalb[s3]"
# Using pip
pip install "libalb[s3]"# Clone the repository
git clone https://github.com/yourusername/libalb.git
cd libalb
# Install with development dependencies
uv pip install -e ".[dev,s3]"from libalb import parse_access_log, parse_access_log_file
# Parse a single log line
log_line = 'https 2018-07-02T22:23:00.186641Z app/my-loadbalancer/...'
entry = parse_access_log(log_line)
print(f"Client: {entry.client_ip}:{entry.client_port}")
print(f"Status: {entry.elb_status_code}")
print(f"Request: {entry.request_method} {entry.request_url}")
# Parse an entire log file
entries = parse_access_log_file('access.log')
for entry in entries:
if entry.elb_status_code >= 500:
print(f"Server error at {entry.timestamp}: {entry.request_url}")from libalb.connection_logs import parse_connection_log_file
entries = parse_connection_log_file('connection.log')
for entry in entries:
print(f"TLS {entry.tls_protocol} with {entry.tls_cipher}")from libalb.s3_reader import list_log_files, read_log_from_s3
from libalb import parse_access_log
# List all log files in a bucket
bucket = 'my-alb-logs'
prefix = 'AWSLogs/123456789012/elasticloadbalancing/us-east-1/'
log_files = list_log_files(bucket, prefix)
# Read and parse logs from S3
for key in log_files:
for line in read_log_from_s3(bucket, key):
entry = parse_access_log(line)
# Process entry...Access logs contain detailed information about requests:
- Client and target IP/port
- Request timing (processing, target, response)
- HTTP status codes
- Request details (method, URL, protocol, user agent)
- TLS information (cipher, protocol)
- Target group ARN and trace ID
Connection logs capture TLS connection information:
- Client IP and port
- TLS protocol and cipher
- Handshake latency
- Client certificate details (if mTLS)
Health check logs track target health:
- Target IP and port
- Health check protocol, port, and path
- Response status and time
- Health status and reason
# Clone and install with dev dependencies
git clone https://github.com/yourusername/libalb.git
cd libalb
uv pip install -e ".[dev,s3]"# Run all tests
pytest
# Run with coverage
pytest --cov=libalb --cov-report=html
# Run only unit tests
pytest tests/unit/
# Run a specific test file
pytest tests/unit/test_access_logs.py# Format code with black
black src/ tests/
# Lint with ruff
ruff check src/ tests/
# Type check with mypy
mypy src/libalb/
├── src/libalb/ # Source code
│ ├── __init__.py # Public API exports
│ ├── access_logs.py # Access log parsing
│ ├── connection_logs.py # Connection log parsing
│ ├── health_logs.py # Health check log parsing
│ └── s3_reader.py # S3 integration
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── conftest.py # Shared fixtures
├── examples/ # Example scripts
├── pyproject.toml # Project metadata and config
└── README.md # This file
This project is structured for effective collaboration with Claude Code:
- Clear module boundaries: Each log type has its own module
- Type hints throughout: Helps Claude understand your intent
- Comprehensive docstrings: Claude can reference documentation
- Test-driven structure: Easy to add tests for new features
- Configuration in pyproject.toml: Single source of truth
- Ask Claude to implement parsing logic for specific log types
- Request new features like filtering, aggregation, or export formats
- Have Claude add tests for new functionality
- Ask for help analyzing log data patterns
MIT License - see LICENSE file for details
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass and code is formatted
- Submit a pull request
- Implement core parsing logic for all log types
- Add filtering and querying capabilities
- Support for streaming large log files
- CLI tool for quick log analysis
- Export to various formats (JSON, CSV, Parquet)
- Integration with pandas DataFrames
- Log aggregation and statistics