Professional Somali phone number validation, formatting & operator detection for Python. A comprehensive library with CLI tools, type hints, and beautiful error handling.
# Sophone 🇸🇴
Professional Somali phone number validation, formatting & operator detection for Python. A comprehensive library with CLI tools, type hints, and beautiful error handling.
## Features
- ✅ **Validate** Somali mobile numbers (+252)
- 🎨 **Format** numbers in multiple styles (local, international, E.164)
- 🏢 **Detect operators** (Hormuud, Somtel, Telesom, etc.)
- 🛡️ **Type-safe** with comprehensive type hints
- 🚀 **CLI tools** for command-line usage
- 📦 **Batch processing** for multiple numbers
- 🎯 **Zero dependencies** - pure Python
## Installation
```bash
pip install sophone
```
## Quick Start
```python
from sophone import validate, normalize_e164, get_operator
# Validate a number
result = validate("+252 61 123 4567")
if result.ok:
print(f"Valid! Operator: {result.value['operator']}")
else:
print(f"Invalid: {result.error['message']}")
# Format to E.164
e164 = normalize_e164("0611234567") # "+252611234567"
# Get operator
operator = get_operator("+252771234567") # "Hormuud"
```
## API Reference
### Core Functions
#### `validate(number: str) -> ValidationResult`
Validates a phone number and returns detailed information.
```python
result = validate("+252 61 123 4567")
# Returns ValidationResult with ok=True/False and value/error
```
#### `is_valid_somali_mobile(number: str) -> bool`
Simple boolean validation.
```python
is_valid = is_valid_somali_mobile("0611234567") # True
```
### Formatting Functions
#### `normalize_e164(number: str) -> str`
Convert to E.164 international format.
```python
e164 = normalize_e164("0611234567") # "+252611234567"
```
#### `format_local(number: str) -> str`
Format to local Somali format.
```python
local = format_local("+252611234567") # "0611 234 567"
```
#### `format_international(number: str) -> str`
Format to international display format.
```python
intl = format_international("0611234567") # "+252 61 123 4567"
```
### Operator Detection
#### `get_operator(number: str) -> str`
Get the operato …