🌟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:

  1. Click the link above to open the example spreadsheet

  2. Make a copy for your own use (File > Make a copy)

  3. Edit your link data in the spreadsheet

  4. When ready to sync, Just select all and copy paste it to a .tsv file.

  5. Use the .tsv file with the sync_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:

  1. Read TSV Data: Parses your TSV file into a structured format

  2. Create Folders: Ensures all needed folders exist in your Short.io account

  3. Identify Changes: Compares TSV data with existing Short.io links

  4. 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 domain

  • file: TSV file containing link data

  • update_if_not_the_same (default: True): Update links that have changed

  • delete_if_not_in_file (default: False): Delete links not present in TSV file

  • real_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
)

Best Practices 🌟¢

  • Start with Dry Runs: Use real_run=False to preview changes before applying them

  • Incremental Mode: Set delete_if_not_in_file=False to only add/update links

  • Full Sync Mode: Set delete_if_not_in_file=True to fully synchronize, removing links not in the TSV

  • Version Control Your TSVs: Keep TSV files in Git for history tracking

  • Incremental Updates: Start with delete_if_not_in_file=False until you’re comfortable

  • Folder 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! πŸš€