# Phone Number Formatter (`dominic-quaiser/phone-number-formatter`) Actor

Easily parse and format phone numbers in bulk with this Apify Actor. Supports E.164, International, National, and RFC3966 formats, configurable regions, batch processing, concurrency, rate limiting, and retries. Ideal for CRMs, SMS campaigns, and data migrations.

- **URL**: https://apify.com/dominic-quaiser/phone-number-formatter.md
- **Developed by:** [Dominic M. Quaiser](https://apify.com/dominic-quaiser) (community)
- **Categories:** Integrations, Developer tools, Open source
- **Stats:** 40 total users, 0 monthly users, 100.0% runs succeeded, 2 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Phone Number Formatter

**Easily parse, validate, and format phone numbers in bulk. Available as both an Apify actor and a standalone Python package.**

This versatile phone number formatting utility supports various international formats (E.164, International, National, RFC3966) and is built for efficiency with configurable batch processing, concurrency, and rate limiting.

Use it as an [Apify actor](https://apify.com/dominic-quaiser/phone-number-formatter) for automated workflows, install it as a Python package for programmatic use, or run it as a CLI tool for local processing.

### 🚀 Features

- **Multiple Distribution Methods:** Use as Apify actor, Python package, or CLI tool
- **Bulk Processing:** Efficiently handles large lists of phone numbers with configurable batching
- **Multiple Output Formats:** Support for standard formats:
  - `E164` (e.g., +16502530000)
  - `INTERNATIONAL` (e.g., +1 650-253-0000)
  - `NATIONAL` (e.g., (650) 253-0000)
  - `RFC3966` (e.g., tel:+1-650-253-0000)
- **Flexible Input:** Accepts phone numbers in various common formats
- **Regional Support:** Set default country/region (ISO 3166-1 alpha-2) for numbers without country codes
- **Performance Optimized:** Concurrent processing with rate limiting and retry mechanisms
- **Open Source:** MIT licensed with full source code available

### 🎯 Use Cases

This tool is ideal for:

- **Data Standardization:** Normalize phone numbers in CRMs, databases, and datasets
- **Application Validation:** Clean and validate user-provided phone numbers
- **Marketing Campaigns:** Prepare phone lists for SMS or calling campaigns
- **Data Migration:** Ensure consistent formatting across system migrations
- **Cost-Effective Automation:** Integrate with workflow platforms (Zapier, Make) as a cheaper alternative to built-in formatting tools
- **Bulk Processing:** Handle thousands of numbers efficiently via API or batch processing

### For Apify Users

#### 📥 Input Parameters

The actor accepts the following input fields. You can provide these as a JSON object when running on the Apify platform or modifying the input configuration.

| Field                  | Type    | Description                                                                                                            | Default Value                                | Required |
| :--------------------- | :------ | :--------------------------------------------------------------------------------------------------------------------- | :------------------------------------------- | :------- |
| `phone_numbers`        | string  | A single string containing phone numbers to format, separated by commas (,), semicolons (;), or new lines (\n).        | `"+49 30 1234567, 555-123-4567, 0123456789"` | Yes      |
| `format_to`            | string  | The desired output format. Options: `E164`, `INTERNATIONAL`, `NATIONAL`, `RFC3966`.                                    | `"E164"`                                     | Yes      |
| `countries`            | string  | The default ISO 3166-1 alpha-2 country code to assume for numbers without an explicit country code (e.g., "US", "GB"). | `"US"`                                       | Yes      |

*For a full list of supported country codes for the `countries` field, please refer to the `input_schema.json` file or common ISO 3166-1 alpha-2 code lists.*

##### **Example Input JSON:**

```json
{
  "phone_numbers": "+44 20 7946 0958; 01632 960984; 415-555-2671\n+1-202-555-0125, (02) 9999 8888",
  "format_to": "INTERNATIONAL",
  "countries": "GB",
  "aggressive_cleaning": true
}
```

#### 📤 Output Data Structure

##### **Example Output Item:**

```json
{
  "index": 0,
  "input": "+44 20 7946 0958",
  "phone_number": "+44 20 7946 0958",
  "success": true,
  "error": null
}
```

#### 💲 Pricing

**1000 results = $0.08**

### Using the Code from GitHub (Local or Package)

The core logic of this phone number formatter can be used directly in your Python projects or run locally via the provided CLI script.

#### 📋 Requirements

- Python 3.8+
- `phonenumbers` library
- Optional: `apify` SDK for actor functionality

#### 📦 Installation & Usage

##### As a Python Package

```bash
git clone https://github.com/dominicquaiser/phone-number-formatter.git
cd phone-number-formatter
pip install -e .
```

**Basic Usage:**

```python
import asyncio
from phone_number_formatter import PhoneFormatter, PhoneFormatterConfig

async def format_numbers():
    # Simple usage with defaults
    formatter = PhoneFormatter()
    results, stats = await formatter.process_phone_numbers(
        "+49 30 1234567, 555-123-4567, 0123456789"
    )
    
    # Custom configuration
    config = PhoneFormatterConfig(
        default_region="GB",
        output_format="INTERNATIONAL",
        batch_size=50,
        max_concurrent_tasks=5
    )
    formatter = PhoneFormatter(config)
    results, stats = await formatter.process_phone_numbers(numbers)

asyncio.run(format_numbers())
```

##### As a CLI Tool

```bash
## Format from direct input
phone-formatter format \
  --run_input '{"phone_numbers": "+1-555-123-4567", "format_to": "E164", "countries": "US"}' \
  --output results.json

## Format from CSV file
phone-formatter csv \
  --csv numbers.csv --column phone_number \
  --format_to INTERNATIONAL --countries GB \
  --output formatted.json
```

##### As an Apify Actor

Deploy to the Apify platform or run via API:

```bash
## Via Apify CLI
apify run

## Via API
curl -X POST https://api.apify.com/v2/acts/azquaier~phone-number-formatter/runs \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"phone_numbers": "+1-555-123-4567", "format_to": "E164", "countries": "US"}'
```

### 📄 License

MIT License - see [LICENSE](https://github.com/dominicquaiser/Phone-Number-Formatter?tab=MIT-1-ov-file) file for details.

### 🛠️ Maintainer

- **Author**: Dominic M. Quaiser
- **Contact**: <mail@dominic-quaiser.io>
- **Website**: [dominic-quaiser.io](https://dominic-quaiser.io/)

# Changelog

This Actor's version history is a separate document: https://apify.com/dominic-quaiser/phone-number-formatter/changelog.md

# Actor input Schema

## `phone_numbers` (type: `string`):

Enter phone numbers to format, separated by commas, semicolons, or new lines.

## `format_to` (type: `string`):

Select the desired output format for the phone numbers.

## `countries` (type: `string`):

Select the default region for parsing phone numbers without a country code.

## Actor input object example

```json
{
  "phone_numbers": "+49 30 1234567, 555-123-4567, 0123456789",
  "format_to": "E164",
  "countries": "US"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("dominic-quaiser/phone-number-formatter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("dominic-quaiser/phone-number-formatter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call dominic-quaiser/phone-number-formatter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,dominic-quaiser/phone-number-formatter"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/oggGdVLDPPCoZVq0O/builds/lQRyrxJjjonHD7Oq3/openapi.json
