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
-
Install Telegram Desktop
- Download from: https://desktop.telegram.org
-
Open Telegram Desktop
-
Navigate to:
Settings → Advanced → Export Telegram Data -
In the export window:
- Check Contacts list
- Uncheck everything else
-
Choose JSON (recommended) or HTML
-
Click Export
-
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)
- Go to https://contacts.google.com
- Click Import
- Upload the generated CSV or VCF
- Sync your phone
Option 2: Direct phone import (VCF)
- Copy
.vcffile to phone - Open it
- 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
Metadata
Release files for tg-contacts 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tg_contacts-1.0.1.tar.gz | 6.0 kB | Without provenance | Details for tg_contacts-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tg_contacts-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for tg_contacts-1.0.1-py3-none-any.whl |
Total release size: 12.6 kB
Release files / tg_contacts-1.0.1.tar.gz
| Download URL | tg_contacts-1.0.1.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9292c66243d6c33907d9ebb9e04ee661f5906a012e4611d6a3fca56f3b096ec
|
|
BLAKE2b-256 checksum How to use checksums |
d18f2cedac71a4d351c3350bba69394faf6ab1148ff8cceefcd83d1bf8a8c0ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / tg_contacts-1.0.1-py3-none-any.whl
| Download URL | tg_contacts-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ae0a1c36dc969d4157a89cf208dc41a6bc4d6b8e5a8c1b37e4999aa7f04bf31
|
|
BLAKE2b-256 checksum How to use checksums |
8e61e8fa1e40022dbe29da9435200dd6efda174982e2c2f25cbef687ab053e90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for tg-contacts 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.