Open source · Python

py-shorten

A lightweight, self-hosted URL shortener built entirely on Python's standard libraries — no heavy frameworks, no bloat.

Python Flask SQLite3 AWS

Try it live

Shorten a URL

How it
came to be

I wanted a URL shortener I could actually own — no third-party services, no rate limits, no branding I didn't choose. So I built one from scratch.

The goal was deliberately constrained: use nothing outside Python's standard library for the core logic. No Requests, no SQLAlchemy, no Redis. Just sqlite3, and a bit of patience.

It started as a weekend project to learn how URL routing and persistence worked at a lower level, and ended up as something genuinely useful I could self-host on a cheap VPS.

How it
works

# 1. Receive a long URL
POST /api/shorten
  body: { "url": "https://..." }

# 2. Hash → 6-char slug
slug = secrets.choice(string.ascii_lowercase + string.digits for _ in range(6))

# 3. Persist in SQLite
INSERT INTO links (slug, url)

# 4. Return short URL
"https://daymons.me/{slug}"

# 5. On visit → 301 redirect
GET /{slug} → 301 original

What I learnt

Working without an ORM taught me a lot about how SQLite actually behaves under concurrent reads — and why connection pooling matters even for tiny projects. I ended up implementing a basic write lock to prevent race conditions on slug generation.

Deploying on AWS with a custom subdomain also pushed me to properly understand DNS TTLs, reverse proxying with Nginx, and writing a systemd service file that survives reboots reliably.

The project is intentionally minimal, but the constraints made it one of the most instructive things I've built.