πSync TSV: The Power Tool for URL Management at Scale πΒΆ
IntroductionΒΆ
Managing dozens, hundreds, or even thousands of shortened URLs can quickly become overwhelming. Thatβs where PyShortIOβs Sync TSV feature comes in - a powerful tool that lets you manage your Short.io links in bulk using simple spreadsheets. This document will showcase how this feature can revolutionize your URL management workflow and provide step-by-step guidance on how to use it effectively.
What is Sync TSV? π€ΒΆ
Sync TSV is a specialized feature of PyShortIO that allows you to:
Create multiple shortened links in one operation
Update existing links in bulk
Delete links no longer needed
Organize links into folders automatically
Maintain a single source of truth for all your shortened URLs
Think of it as a synchronization bridge between your local data (in a TSV file) and your Short.io account.
TSV File Format πΒΆ
A TSV (Tab-Separated Values) file defines all the links you want to manage. Each row represents a link with its properties:
example.tsv
1original_url title path tags folder_name allow_duplicates clicks_limit cloaking password password_contact redirect_type ttl expire_at expire_url utm_source utm_medium utm_campaign utm_term utm_content android_url iphone_url skip_qs archived split_url split_percent integration_adroll integration_fb integration_ga integration_gtm
2https://short.io/pricing/ Short io pricing short.io, pricing Short IO
3https://short.io/features/ Short io features short.io, features Short IO
4https://short.io/integrations/ Short io integrations short.io, integrations Short IO
5https://www.python.org/ Python Org python Python
6https://example.com/
Using Google Sheets as Your TSV EditorΒΆ
For convenient editing and collaboration, you can use Google Sheets as your TSV editor:
Example Short.io Links Template
To use this template:
Click the link above to open the example spreadsheet
Make a copy for your own use (File > Make a copy)
Edit your link data in the spreadsheet
When ready to sync, Just select all and copy paste it to a
.tsvfile.Use the
.tsvfile with thesync_tsv()method
This approach makes it easy to collaborate with team members on link management while maintaining a structured format for PyShortIO.
Getting Started with Sync TSV πΒΆ
Step 1: Create a Simple TSV File
Create your first TSV file (links1.tsv) with a few links:
links1.tsv
1original_url title path tags folder_name allow_duplicates clicks_limit cloaking password password_contact redirect_type ttl expire_at expire_url utm_source utm_medium utm_campaign utm_term utm_content android_url iphone_url skip_qs archived split_url split_percent integration_adroll integration_fb integration_ga integration_gtm
2https://short.io/pricing/ Short io pricing short.io, pricing Short IO
3https://short.io/features/ Short io features short.io, features Short IO
4https://short.io/integrations/ Short io integrations short.io, integrations Short IO
5https://www.python.org/ Python Org python Python
6https://example.com/
Step 2: Run Your First Sync
# Install with sync dependencies
# pip install pyshortio[sync]
from pathlib import Path
import pyshortio.api as pyshortio
# Initialize client with your API token
client = pyshortio.Client(token="your_api_token")
# Your short.io domain
hostname = "yourdomain.short.gy"
# Sync from TSV file
with open("links1.tsv", "r") as file:
client.sync_tsv(
hostname=hostname,
file=file,
update_if_not_the_same=True,
delete_if_not_in_file=False, # Set to True to delete links not in the TSV file
real_run=True,
)
The output log would looks like this:
log1.txt
1+----- π π Start 'Sync links from TSV file to short.io' -----------------------+
2π
3π hostname = 'pyshortio.short.gy'
4π update_if_not_the_same = True
5π delete_if_not_in_file = True
6π +----- π π Start 'Read link data from TSV file' -----------------------------+
7π π
8π π Read data ...
9π π Check original_url column ...
10π π Process tags column ...
11π π Got 5 rows
12π π Got 2 unique folder names
13π π
14π +----- β° β
π End 'Read link data from TSV file', elapsed = 0.04 sec ---------+
15π +----- π π Start 'Create folder if they do not exists' ----------------------+
16π π
17π π Read existing folder info from short.io ...
18π π Got 2 existing folders
19π π 'Python' folder already exists
20π π 'Short IO' folder already exists
21π π
22π +----- β° β
π End 'Create folder if they do not exists', elapsed = 0.17 sec -----+
23π +----- π π Start 'Identify link to create, update and delete' ---------------+
24π π
25π π Read existing link info from short.io ...
26π π Got 0 existing links
27π π π’ got 5 links to create
28π π π‘ got 0 links to update
29π π π΄ got 0 links to delete
30π π To create: link_data = {'original_url': 'https://short.io/pricing/', 'title': 'Short io pricing', 'tags': ['pricing', 'short.io'], 'folder_id': 'BgG2lQ2kQwLHa4TepHU8P'}
31π π To create: link_data = {'original_url': 'https://short.io/features/', 'title': 'Short io features', 'tags': ['features', 'short.io'], 'folder_id': 'BgG2lQ2kQwLHa4TepHU8P'}
32π π To create: link_data = {'original_url': 'https://short.io/integrations/', 'title': 'Short io integrations', 'tags': ['integrations', 'short.io'], 'folder_id': 'BgG2lQ2kQwLHa4TepHU8P'}
33π π To create: link_data = {'original_url': 'https://www.python.org/', 'title': 'Python Org', 'tags': ['python'], 'folder_id': 'JR_S7CWHpfBqNZCYa2EzO'}
34π π To create: link_data = {'original_url': 'https://example.com/'}
35π π
36π +----- β° β
π End 'Identify link to create, update and delete', elapsed = 0.16 sec -----+
37π +----- π π’ Start 'Create links' ---------------------------------------------+
38π π’
39π π’ create link for original_url = https://short.io/pricing/
40π π’ create link for original_url = https://short.io/features/
41π π’ create link for original_url = https://short.io/integrations/
42π π’ create link for original_url = https://www.python.org/
43π π’ create link for original_url = https://example.com/
44π π’
45π +----- β° β
π’ End 'Create links', elapsed = 0.66 sec -------------------------+
46π
47+----- β° β
π End 'Sync links from TSV file to short.io', elapsed = 1.20 sec -----+
Step 3: Verify Your Links in Short.io
Log into your Short.io account and confirm that your links have been created successfully.
Understanding the Sync Process πΒΆ
When you run sync_tsv(), PyShortIO follows these steps:
Read TSV Data: Parses your TSV file into a structured format
Create Folders: Ensures all needed folders exist in your Short.io account
Identify Changes: Compares TSV data with existing Short.io links
Apply Changes: Creates, updates, and/or deletes links as needed
Incremental Updates with Sync TSV πΒΆ
One of the most powerful aspects of Sync TSV is the ability to make incremental updates. Letβs see how to update our links with a new TSV file (links2.tsv):
links2.tsv
1original_url title path tags folder_name allow_duplicates clicks_limit cloaking password password_contact redirect_type ttl expire_at expire_url utm_source utm_medium utm_campaign utm_term utm_content android_url iphone_url skip_qs archived split_url split_percent integration_adroll integration_fb integration_ga integration_gtm
2https://short.io/pricing/ Short io pricing short.io, pricing Short IO
3https://short.io/pricing/?utm_medium=linkedin Short io pricing short.io, pricing Short IO linkedin
4https://short.io/pricing/?utm_medium=twitter Short io pricing short.io, pricing Short IO twitter
5https://short.io/pricing/?utm_medium=reddit Short io pricing short.io, pricing Short IO reddit
6https://short.io/features/ Short io features short.io, features Short IO
7https://short.io/integrations/ Short io integrations short.io, integrations Short IO
8https://www.python.org/ Python Org python-org python Python
9https://example.com/
# Second sync with updated TSV file
with open("links2.tsv", "r") as file:
client.sync_tsv(
hostname=hostname,
file=file,
update_if_not_the_same=True,
delete_if_not_in_file=True,
real_run=True,
)
The output log would looks like this:
log2.txt
1+----- π π Start 'Sync links from TSV file to short.io' -----------------------+
2π
3π hostname = 'pyshortio.short.gy'
4π update_if_not_the_same = True
5π delete_if_not_in_file = True
6π +----- π π Start 'Read link data from TSV file' -----------------------------+
7π π
8π π Read data ...
9π π Check original_url column ...
10π π Process tags column ...
11π π Got 8 rows
12π π Got 2 unique folder names
13π π
14π +----- β° β
π End 'Read link data from TSV file', elapsed = 0.01 sec ---------+
15π +----- π π Start 'Create folder if they do not exists' ----------------------+
16π π
17π π Read existing folder info from short.io ...
18π π Got 2 existing folders
19π π 'Python' folder already exists
20π π 'Short IO' folder already exists
21π π
22π +----- β° β
π End 'Create folder if they do not exists', elapsed = 0.15 sec -----+
23π +----- π π Start 'Identify link to create, update and delete' ---------------+
24π π
25π π Read existing link info from short.io ...
26π π Got 5 existing links
27π π π’ got 3 links to create
28π π π‘ got 1 links to update
29π π π΄ got 0 links to delete
30π π To create: link_data = {'original_url': 'https://short.io/pricing/?utm_medium=linkedin', 'title': 'Short io pricing', 'tags': ['pricing', 'short.io'], 'utm_medium': 'linkedin', 'folder_id': 'BgG2lQ2kQwLHa4TepHU8P'}
31π π To create: link_data = {'original_url': 'https://short.io/pricing/?utm_medium=twitter', 'title': 'Short io pricing', 'tags': ['pricing', 'short.io'], 'utm_medium': 'twitter', 'folder_id': 'BgG2lQ2kQwLHa4TepHU8P'}
32π π To create: link_data = {'original_url': 'https://short.io/pricing/?utm_medium=reddit', 'title': 'Short io pricing', 'tags': ['pricing', 'short.io'], 'utm_medium': 'reddit', 'folder_id': 'BgG2lQ2kQwLHa4TepHU8P'}
33π π To update: link_id = 'lnk_5Dae_DoultcXz5jO9HSCn26amm', link_data = {'original_url': 'https://www.python.org/', 'title': 'Python Org', 'path': 'python-org', 'tags': ['python'], 'folder_id': 'JR_S7CWHpfBqNZCYa2EzO'}
34π π
35π +----- β° β
π End 'Identify link to create, update and delete', elapsed = 0.18 sec -----+
36π +----- π π’ Start 'Create links' ---------------------------------------------+
37π π’
38π π’ create link for original_url = https://short.io/pricing/?utm_medium=linkedin
39π π’ create link for original_url = https://short.io/pricing/?utm_medium=twitter
40π π’ create link for original_url = https://short.io/pricing/?utm_medium=reddit
41π π’
42π +----- β° β
π’ End 'Create links', elapsed = 0.26 sec -------------------------+
43π +----- π π‘ Start 'Update links' ---------------------------------------------+
44π π‘
45π π‘ update link lnk_5Dae_DoultcXz5jO9HSCn26amm, original_url = https://www.python.org/
46π π‘
47π +----- β° β
π‘ End 'Update links', elapsed = 0.21 sec -------------------------+
48π
49+----- β° β
π End 'Sync links from TSV file to short.io', elapsed = 0.97 sec -----+
Understanding Sync Parameters βοΈΒΆ
hostname: Your Short.io domainfile: TSV file containing link dataupdate_if_not_the_same(default: True): Update links that have changeddelete_if_not_in_file(default: False): Delete links not present in TSV filereal_run(default: True): Actually apply changes (set to False for dry-run)
Advanced Use Cases π₯ΒΆ
Dry Run ModeΒΆ
Before applying changes to your production domain, run in dry-run mode:
client.sync_tsv(
hostname=hostname,
file=file,
real_run=False, # Simulate changes without applying them
)
Automated Link ManagementΒΆ
Incorporate Sync TSV into your automated workflows:
# Example: Daily sync job
def daily_link_sync():
# Generate TSV from your database
generate_tsv_from_database()
# Sync to Short.io
with open("generated_links.tsv", "r") as file:
client.sync_tsv(
hostname=hostname,
file=file,
update_if_not_the_same=True,
delete_if_not_in_file=True,
)
Best Practices πΒΆ
Start with Dry Runs: Use
real_run=Falseto preview changes before applying themIncremental Mode: Set
delete_if_not_in_file=Falseto only add/update linksFull Sync Mode: Set
delete_if_not_in_file=Trueto fully synchronize, removing links not in the TSVVersion Control Your TSVs: Keep TSV files in Git for history tracking
Incremental Updates: Start with
delete_if_not_in_file=Falseuntil youβre comfortableFolder Organization: Use the folder_name column to keep links organized
Automated Testing: Validate your TSV files before syncing
Troubleshooting π§ΒΆ
Common Issues
Missing Required Columns: Ensure your TSV has at least the original_url column
Duplicate URLs: Each original URL must be unique in your TSV
Permission Errors: Verify your API token has write permissions
Folder Creation Failures: Ensure folder names are valid
Reading LogsΒΆ
The sync process produces detailed logs that can help identify issues:
π’ indicates links to be created
π‘ indicates links to be updated
π΄ indicates links to be deleted
ConclusionΒΆ
Sync TSV transforms how you manage shortened URLs at scale. Whether youβre managing marketing campaigns with dozens of tracking links or maintaining a knowledge base with hundreds of references, this feature makes bulk URL management simple, reliable, and efficient.
Get started today with PyShortIO and leave manual link management behind! π