Haiwaibiji logoHaiwaibiji中文

URL Shortening — How to Batch-Process 100 Long Links Offline

Nolan聊5 min readTools

Do social media for any length of time and you'll notice everyone's FB and Instagram posts use short links — easier to click, easier to spread. Online generators are easy to find, but the drawbacks are obvious: 1. no batching; 2. the domain isn't yours.

The URL shortening market

Digging around, URL shortening turns out to be a genuinely interesting tool market, with Bitly the overseas leader. Free services for converting long URLs include (international services listed; domestic ones are a search away):

URL shortening

Popular tools:

  1. Bitly: the most popular service, supports custom links; registered users get click analytics. Visit Bitly
  2. TinyURL: create short links without registering; partial customization supported. Visit TinyURL
  3. Rebrandly: custom-domain short links for brands; free tier is limited. Visit Rebrandly
  4. Google's shortener: officially migrated to Firebase Dynamic Links — with a Firebase project you can create short links. Visit Firebase
  5. Ow.ly: Hootsuite's shortener, suited to social media management and click tracking. Visit Ow.ly
  6. Browser extensions: extensions like "Short URL" generate short links right in the browser.

All of them: paste the long link, click, get the short one.

Using the Bitly API — Python example. Register for a Bitly API Access Token, then install requests:

pip install requests

The code:

import requests

def shorten_url(long_url):
    # your Bitly Access Token
    access_token = "YOUR_BITLY_ACCESS_TOKEN"
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json"
    }
    payload = {"long_url": long_url}
    response = requests.post("https://api-ssl.bitly.com/v4/shorten", json=payload, headers=headers)
    if response.status_code == 200:
        return response.json().get("link")
    else:
        print("Error:", response.status_code, response.text)
        return None

# usage
long_url = "https://www.yourwebsite.com/some/very/long/url"
short_url = shorten_url(long_url)
print("Short URL:", short_url)

Replace "YOUR_BITLY_ACCESS_TOKEN" with your token; short_url is the generated link.

Free batch shortening with pyshorteners

pyshorteners is a lightweight Python library supporting multiple shortening services:

pip install pyshorteners

Then:

import pyshorteners

def shorten_url(long_url):
    s = pyshorteners.Shortener()
    return s.tinyurl.short(long_url)

# usage
long_url = "https://www.yourwebsite.com/some/very/long/url"
print("Short URL:", shorten_url(long_url))

Bitly vs pyshorteners

Bitly API pros and cons

Pros:

  1. Analytics: click statistics — geography, device type — great for behavior analysis.
  2. Branding: premium tiers support custom domains for professional, branded links.
  3. Stability: a veteran service; highly reliable, rarely down.

Cons:

  1. API token: registration and key management add setup steps.
  2. Free-tier caps: monthly link limits; fine personally, pricey at scale.
  3. API dependency: heavy use requires rate-limit management.

Best for: users needing branded links and click analytics — especially heavy social promotion.

pyshorteners pros and cons

Pros:

  1. Instant: no account, no keys — install and go.
  2. Free and unlimited: TinyURL's free tier has no volume cap; friendly for personal use.
  3. Multiple backends: supports different providers (Is.gd, Bitly, etc.).

Cons:

  1. No analytics: no click or behavior data.
  2. Weak branding: default TinyURL domain; suited to throwaway links.
  3. Variable stability: TinyURL is decent, but free providers can have outages or frequent maintenance.

Best for: small personal projects, no tracking needed — temporary shares, personal shortcuts.

Comparison

MethodAnalyticsBrandingSetup barrierStabilityUse case
Bitly APIYesYesHigherHighBusiness, click analysis
pyshorteners (TinyURL)NoNoLowDecentPersonal, temporary links

Recommendation:

  • Need analytics and branded links: Bitly.
  • Just need quick short links with zero friction: pyshorteners.

Batch shortening from Excel

Batch work means Excel. Here's code that reads long links from column A and writes short links to column C (column B holds my IDs — adjust to taste).

Use pandas to read/write Excel and pyshorteners to generate.

Prerequisites

pip install pandas pyshorteners openpyxl

Code

Assuming your file is urls.xlsx with long URLs in column A:

import pandas as pd
import pyshorteners

def shorten_urls_in_excel(file_path):
    # read the Excel file
    df = pd.read_excel(file_path)
    # init the shortener
    shortener = pyshorteners.Shortener()
    # walk column A, writing short links to a new column
    df['Shortened URL'] = df.iloc[:, 0].apply(lambda x: shortener.tinyurl.short(x) if pd.notnull(x) else None)
    # save back
    df.to_excel(file_path, index=False)

# usage
shorten_urls_in_excel('urls.xlsx')

How it works

  1. Reads the Excel file into a DataFrame.
  2. apply() walks column A, shortening each URL into a new "Shortened URL" column.
  3. Saves the DataFrame back to the same file.

Run it, and column C holds the short links.

Yes — it depends on the API's settings. For long-term business use, a paid API is recommended to keep links alive and observable.

Any online generator recommendations?

They're all similar. In China, Chinaz has one.