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

⚠️ Note: Version 1.0.0 had a packaging issue. Please use 1.0.1 or newer.

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.1.tar.gz (6.0 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.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tg_contacts-1.0.1.tar.gz
  • Upload date:
  • Size: 6.0 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.1.tar.gz
Algorithm Hash digest
SHA256 a9292c66243d6c33907d9ebb9e04ee661f5906a012e4611d6a3fca56f3b096ec
MD5 1afaa28a4e7705f29c49c88a00131192
BLAKE2b-256 d18f2cedac71a4d351c3350bba69394faf6ab1148ff8cceefcd83d1bf8a8c0ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tg_contacts-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ae0a1c36dc969d4157a89cf208dc41a6bc4d6b8e5a8c1b37e4999aa7f04bf31
MD5 7c4eb2750295a62959337783c2c092ff
BLAKE2b-256 8e61e8fa1e40022dbe29da9435200dd6efda174982e2c2f25cbef687ab053e90

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