Skip to main content

Telegram contacts JSON to Android-ready CSV/VCF converter

Project description

tg-contacts

tg-contacts is a command-line tool that converts Telegram contact exports (JSON) into Android-ready CSV or VCF files.

It cleans, normalizes, deduplicates, and formats phone numbers so they import cleanly into Google Contacts / Android.


Key Features

  • Supports Telegram JSON exports

  • Output formats:

    • CSV (Google Contacts compatible)
    • VCF / vCard 3.0 (Android-preferred)
  • Phone number normalization:

    • 00XXXXXXXX+XXXXXXXX
    • Local → international via country code
  • Country-aware formatting (--country KE)

  • Deduplication by phone number

  • Flexible name output modes

  • Colored CLI output (optional)

  • Progress bar for large exports

  • Beautiful summary statistics

  • Zero external dependencies


📥 Installation

pip install tg-contacts

Verify installation:

tg-contacts --help

📤 Getting Your Contacts from Telegram

You must first export your contacts using Telegram Desktop.

Step-by-step: Export contacts from Telegram

  1. Install Telegram Desktop

  2. Open Telegram Desktop

  3. Navigate to:

    Settings → Advanced → Export Telegram Data
    
  4. In the export window:

    • Check Contacts list
    • Uncheck everything else
  5. Choose JSON (recommended) or HTML

  6. Click Export

  7. After export completes:

    • Locate the exported folder

    • Find a file similar to:

      result.json
      

This JSON file is your input for tg-contacts.


Basic Usage

tg-contacts -i result.json

➡ Creates a timestamped CSV file:

android_contacts_YYYYMMDD_HHMMSS.csv

Output Formats

CSV (default)

tg-contacts -i result.json --format csv

Best for:

  • Google Contacts web import
  • Spreadsheet editing

VCF (recommended for Android/iOS)

tg-contacts -i result.json --format vcf

Best for:

  • Direct Android or iOS imports
  • Preserving contact metadata

Country-Based Phone Normalization

Automatically converts local numbers into international format.

Example (Kenya)

tg-contacts -i result.json --country KE
Input Output
0701234567 +254701234567
701234567 +254701234567
00254701234567 +254701234567

Currently supported:

  • KE (Kenya)

(More countries can be added, I focused on my use case.)


Deduplication

Remove duplicate contacts based on phone number.

tg-contacts -i result.json --dedupe phone
  • Keeps the first occurrence
  • Reports number of duplicates removed

Name Output Modes

Control which name fields are included.

--name-mode both   # Default
--name-mode first
--name-mode last

Examples

tg-contacts -i result.json --name-mode first
tg-contacts -i result.json --name-mode last

Colored Output

Colored output is enabled by default.

Disable it if piping output or on unsupported terminals:

tg-contacts -i result.json --no-color

Custom Output File

tg-contacts -i result.json -o my_contacts.vcf

If omitted, a timestamped filename is generated automatically.


Final Summary Statistics

At the end of every run, you’ll see:

  • Total input contacts
  • Written contacts
  • Duplicates removed
  • Numbers normalized (00 → +)
  • Numbers normalized via country
  • Output format
  • Output file path

Example:

[+] Summary
• Input contacts        : 512
• Written contacts      : 487
• Duplicates removed    : 25
• 00 → + normalized     : 38
• Country normalized    : 412
• [-] Output format         : VCF

Importing into Android

Option 1: Google Contacts (recommended)

  1. Go to https://contacts.google.com
  2. Click Import
  3. Upload the generated CSV or VCF
  4. Sync your phone

Option 2: Direct phone import (VCF)

  1. Copy .vcf file to phone
  2. Open it
  3. Import into Contacts

Example Power Commands

tg-contacts -i result.json --country KE --dedupe phone --format vcf
tg-contacts -i result.json --name-mode first --format csv

Privacy & Security

  • All processing is local
  • No network calls
  • No data leaves your machine
  • Safe for sensitive contact lists

Development

Clone and run locally:

git clone https://github.com/yournamejohntroony/tg-contacts
cd tg-contacts
pip install -e .

License

MIT License


Roadmap

  • More country codes
  • Auto country detection
  • Interactive mode
  • GUI version
  • Homebrew & Windows builds

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

tg_contacts-1.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

tg_contacts-1.0.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file tg_contacts-1.0.0.tar.gz.

File metadata

  • Download URL: tg_contacts-1.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for tg_contacts-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dbf8653f9b33f331f928442a999afc496ddeb6c0bcad09e39ac788f73c5cace6
MD5 b002e7e722cea3b0cdb1d18eb39a1fb0
BLAKE2b-256 09c052e77cf6dd004346e5fe46a36e9b4c8e85d1baa2122efa2064d275be280b

See more details on using hashes here.

File details

Details for the file tg_contacts-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tg_contacts-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for tg_contacts-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f04bc8c6dfe4e78fcc4c44354a98fe65bb648ede8b223e1b1c19cc7e0dafed2
MD5 7139c7d997e27b8e5ee9eb217904ae49
BLAKE2b-256 b6731824fd8add106771b82f0c8e9fbedf5b804dce59face27e26882c8126193

See more details on using hashes here.

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