Skip to main content

Landline Scrubber core library - phone verification and DNC checking

Project description

AI LLS Library

Core business logic library and CLI tools for Landline Scrubber - phone verification and DNC checking.

Version 2.1.0 - Streaming & Provider Architecture

New features:

  • Streaming support for large CSV files to reduce memory usage
  • Provider architecture for clean separation of verification logic
  • Contract tests ensuring all providers behave consistently

Version 2.0.0 - Breaking Changes

This is a greenfield rewrite with no backwards compatibility:

  • All file-based CSV processing replaced with text-based methods
  • Removed _sync suffix from all methods (everything is sync)
  • process_csv_sync(file_path)process_csv(csv_text)
  • generate_results_csv(...) now returns CSV string instead of writing to file

Features

  • Phone number normalization (E.164 format)
  • Line type detection (mobile/landline/voip)
  • DNC (Do Not Call) list checking
  • DynamoDB caching with 30-day TTL
  • Bulk CSV processing
  • Infrastructure-aware CLI for admin operations
  • AWS Lambda PowerTools integration

Installation

# Install library with Poetry
poetry install

# Install CLI globally
pip install -e .

Library Usage

Single Phone Verification

from ai_lls_lib import PhoneVerifier, DynamoDBCache

cache = DynamoDBCache(table_name="phone-cache")
verifier = PhoneVerifier(cache)

result = verifier.verify("+15551234567")
print(f"Line type: {result.line_type}")
print(f"DNC: {result.dnc}")
print(f"From cache: {result.cached}")

Bulk Processing

from ai_lls_lib import BulkProcessor, PhoneVerifier, DynamoDBCache

cache = DynamoDBCache(table_name="phone-cache")
verifier = PhoneVerifier(cache)
processor = BulkProcessor(verifier)

# Process CSV text content
csv_text = "name,phone\nJohn,+15551234567\nJane,+15551234568"
results = processor.process_csv(csv_text)

# Generate results CSV
results_csv = processor.generate_results_csv(csv_text, results)
print(results_csv)  # CSV string with added line_type, dnc, cached columns

Streaming Large Files

For memory-efficient processing of large CSV files:

from ai_lls_lib import BulkProcessor, PhoneVerifier, DynamoDBCache

cache = DynamoDBCache(table_name="phone-cache")
verifier = PhoneVerifier(cache)
processor = BulkProcessor(verifier)

# Process CSV as a stream, yielding batches
csv_lines = open('large_file.csv').readlines()
for batch in processor.process_csv_stream(csv_lines, batch_size=100):
    print(f"Processed batch of {len(batch)} phones")
    # Each batch is a list of PhoneVerification objects

Custom Verification Providers

Use different verification providers based on your needs:

from ai_lls_lib import PhoneVerifier, DynamoDBCache
from ai_lls_lib.providers import StubProvider

# Use stub provider for testing
cache = DynamoDBCache(table_name="phone-cache")
provider = StubProvider()  # Deterministic testing provider
verifier = PhoneVerifier(cache, provider=provider)

# When external APIs are ready, switch to:
# from ai_lls_lib.providers.external import ExternalAPIProvider
# provider = ExternalAPIProvider(phone_api_key="...", dnc_api_key="...")

CLI Usage

The ai-lls CLI provides infrastructure-aware administrative tools:

Verification Commands

# Verify single phone
ai-lls verify phone +15551234567 --stack landline-api

# Bulk verify CSV
ai-lls verify bulk input.csv -o output.csv --stack landline-api

Cache Management

# Show cache statistics
ai-lls cache stats --stack landline-api

# Get cached entry
ai-lls cache get +15551234567 --stack landline-api

# Invalidate cache entry
ai-lls cache invalidate +15551234567 --stack landline-api

# Clear old entries
ai-lls cache clear --older-than 20 --stack landline-api

Administrative Commands

# Manage user credits
ai-lls admin user-credits user123 --add 100
ai-lls admin user-credits user123 --set 500

# List API keys
ai-lls admin api-keys --user user123

# Check queue status
ai-lls admin queue-stats

# View secrets (masked)
ai-lls admin secrets --stack landline-api

Test Stack Management

# Deploy test stack
ai-lls test-stack deploy

# Check status
ai-lls test-stack status

# Run integration tests
ai-lls test-stack test

# Delete test stack
ai-lls test-stack delete

Project Structure

ai-lls-lib/
├── src/ai_lls_lib/
│   ├── core/           # Business logic (infrastructure-agnostic)
│   │   ├── models.py   # Pydantic models
│   │   ├── verifier.py # Phone verification
│   │   ├── processor.py # Bulk processing
│   │   └── cache.py    # DynamoDB cache
│   ├── cli/            # Infrastructure-aware CLI
│   │   ├── __main__.py # Entry point
│   │   ├── commands/   # Command modules
│   │   └── aws_client.py # AWS operations
│   └── testing/        # Test utilities
│       └── fixtures.py # Test data
├── tests/
│   ├── unit/          # Mocked tests
│   └── integration/   # AWS integration tests
└── test-stack.yaml    # Test infrastructure

Testing

# Run unit tests (mocked AWS)
poetry run pytest tests/unit -v

# Deploy test stack for integration tests
ai-lls test-stack deploy

# Run integration tests (requires test stack)
TEST_STACK_NAME=ai-lls-lib-test poetry run pytest tests/integration -v

# All tests with coverage
poetry run pytest --cov=src --cov-report=html

# Clean up
ai-lls test-stack delete

Development

Current Stub Implementation

For demo purposes, verification uses stub logic based on last digit:

  • Ends in 3: mobile, not on DNC
  • Ends in 2: landline, not on DNC
  • Ends in 1: mobile, on DNC
  • Ends in 0: landline, on DNC
  • Otherwise: mobile, not on DNC

TODO markers indicate where real API integration will be added.

Code Quality

# Format code
poetry run black src/ tests/
poetry run isort src/ tests/

# Type checking
poetry run mypy src/

# Run pre-commit hooks
pre-commit run --all-files

Environment Variables

  • DNC_API_KEY - DNC verification API key
  • DNC_CHECK_API_KEY - Alternative DNC service
  • PHONE_VERIFY_API_KEY - Line type verification
  • AWS_REGION - AWS region (default: us-east-1)
  • AWS_PROFILE - AWS profile for CLI operations

License

Proprietary - All rights reserved

Release Process

This library uses semantic versioning and publishes to:

  • TestPyPI on dev branch pushes (pre-release versions)
  • PyPI on main branch pushes (stable releases)

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

ai_lls_lib-1.4.0rc4.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

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

ai_lls_lib-1.4.0rc4-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file ai_lls_lib-1.4.0rc4.tar.gz.

File metadata

  • Download URL: ai_lls_lib-1.4.0rc4.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_lls_lib-1.4.0rc4.tar.gz
Algorithm Hash digest
SHA256 eb2d0bfe44e78930ba74b9a5f9ebd1dd20a9a820c8f580000b9aded33b97a9f3
MD5 0c4239f29a82967b3ae9c650f43d637c
BLAKE2b-256 95aa8c61e2ee981ac492e64bfd7513f0932bad716a5bd840eced474b5223ed78

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_lls_lib-1.4.0rc4.tar.gz:

Publisher: libs-pipeline.yml on svange/landline-scrubber

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_lls_lib-1.4.0rc4-py3-none-any.whl.

File metadata

  • Download URL: ai_lls_lib-1.4.0rc4-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_lls_lib-1.4.0rc4-py3-none-any.whl
Algorithm Hash digest
SHA256 c1f448a1fe2ae3df33a763172840b2b73019dfbd2190de4f925f01dc31cff75a
MD5 c8fac00baf9ca9cf1212fb02fc2460e2
BLAKE2b-256 cb79e03402b89c5f17f8d96a001ffd5c109e837b889773843fbadaa54202cb96

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_lls_lib-1.4.0rc4-py3-none-any.whl:

Publisher: libs-pipeline.yml on svange/landline-scrubber

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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