Botmonster Tech
AI Smart Home Self-Hosting Coding Web Dev Hardware jQuery Bootpag Image2SVG Tags
Botmonster Tech
AISmart HomeSelf-HostingCodingWeb DevHardwarejQuery BootpagImage2SVGTags
URL Shortener in 200 Lines of Python

URL Shortener in 200 Lines of Python

I’ll show you how to build a real URL shortener in under 200 lines of Python. We’re going to use FastAPI for the web layer, SQLite for storage, and base62 encoding for short codes. I’ll walk you through a redirect endpoint, a click counter, and rate limiting with SlowAPI . In my experience, this simple stack handles millions of links on one server.

Key Takeaways

  • Build a production-ready URL shortener with fewer than 200 lines of Python.
  • Use SQLite for zero-config storage that handles thousands of requests per second.
  • Implement base62 encoding to turn database IDs into short, clean strings.
  • Protect your service with SlowAPI rate limiting to block spam bots.
  • Deploy the entire app in a 50 MB Docker container behind a Caddy reverse proxy.

Architecture and Tech Stack Choices

Before I write any code, I want to walk you through why I picked this stack. Picking the wrong stack for a small project either over-engineers it or under-builds it. I’ve seen systems fall over at a few hundred users, and I want to help you avoid that.

SQLite at the Edge: 100x Faster Reads, Cloudflare D1 and LiteFS

SQLite at the Edge: 100x Faster Reads, Cloudflare D1 and LiteFS

SQLite can now run at the edge - inside Cloudflare Workers via D1, on Fly.io via LiteFS replicated volumes, and in any V8 isolate through embedded WASM builds. This gives you sub-millisecond read queries by placing your database physically close to your users on a global CDN. The key innovations that made this practical are LiteFS for transparent SQLite replication across distributed nodes, Cloudflare D1 as a managed edge SQLite service, Turso with its libSQL fork adding server mode and built-in replication, and Litestream for continuous WAL-based streaming to S3. Combined with SQLite’s zero-dependency, single-file architecture, you get a relational database that deploys as part of your application binary, needs no connection pooling, and handles thousands of reads per second per node with microsecond-level latency.

Python Markdown Blog: 100 Lines of Code

Python Markdown Blog: 100 Lines of Code

You can build a working static site generator in about 100 lines of Python. The result reads Markdown files from a content directory, parses their YAML front matter, converts the Markdown to HTML, wraps everything in Jinja2 templates, and writes the output to a public/ folder ready to be served by any web server. It is the same fundamental pipeline that powers tools like Hugo , Jekyll , and Eleventy - just stripped down to the essentials so you can see exactly how the pieces fit together.

WCAG 2.2 Web Forms: Error Handling, Validation, ARIA

WCAG 2.2 Web Forms: Error Handling, Validation, ARIA

Accessible web forms start with semantic HTML and use ARIA only to fill gaps native elements can’t reach. Use aria-live for error announcements and aria-describedby to link messages to fields. Following WCAG 2.2 AA ensures every user can perceive, navigate, and complete your forms using only a keyboard.

Most form accessibility failures are not caused by missing ARIA. They come from developers skipping basic HTML semantics like labels and fieldsets. Patching this damage with ARIA often makes things worse. The W3C’s first rule is simple: no ARIA is better than bad ARIA. Misapplied roles or redundant labels create noise instead of clarity.

Monorepo Management with Turborepo: A Practical Guide

Monorepo Management with Turborepo: A Practical Guide

Turborepo is a high-performance build system for JavaScript and TypeScript monorepos. It uses content-aware caching, parallel task execution, and dependency-aware task ordering to make multi-package repositories fast and practical to work with. You define your workspace packages in a pnpm-workspace.yaml file (or npm/yarn workspaces), configure a turbo.json that declares task dependencies and caching behavior, and Turborepo handles the rest. Running turbo run build only rebuilds packages whose source files have actually changed, with cache hits restoring build outputs in milliseconds instead of minutes.

Type-Safe APIs with Pydantic v3 and FastAPI: A Best Practices Guide

Type-Safe APIs with Pydantic v3 and FastAPI: A Best Practices Guide

Pydantic v3 shipped in late 2025. It has a new Rust-backed core and a fresh model system. With FastAPI 0.115+, you get auto request checks, fast JSON output, and OpenAPI 3.1 docs. No manual schema work. Data errors get caught at the API edge. Client SDKs come from the live spec. The check overhead that used to be a bottleneck is now mostly gone.

This guide walks through what changed in v3, how to lay out a production project, the validation patterns to know, and what deployment looks like when you care about speed.

  • ◀︎
  • 1
  • 2
  • 3
  • 4
  • ▶︎

Most Popular

Wildcard SSL Certificates with Let's Encrypt and DNS-01

Wildcard SSL Certificates with Let's Encrypt and DNS-01

Wildcard SSL certs from Let's Encrypt use DNS-01 or the new DNS-PERSIST-01 challenge. Certbot and acme.sh automate the process; systemd timers run renewal.

CSS Anchor Positioning: Replace Floating UI With CSS

CSS Anchor Positioning: Replace Floating UI With CSS

CSS Anchor Positioning pins tooltips and popovers to elements using pure CSS. Replace JavaScript positioning libraries with native browser anchor APIs.

WCAG 2.2 Web Forms: Error Handling, Validation, ARIA

WCAG 2.2 Web Forms: Error Handling, Validation, ARIA

Build WCAG 2.2 AA-compliant web forms with semantic HTML, ARIA attributes, real-time inline validation, and clear error message summaries for all users.

Self-Host Plausible Analytics: 1 KB Script, No Cookies

Self-Host Plausible Analytics: 1 KB Script, No Cookies

Self-host Plausible on a cheap VPS with Docker Compose: 1 KB gzipped privacy-first tracking script, zero cookies. Complete Google Analytics alternative.

Tailwind v4: Oxide Rust Engine, 182x Incremental Builds, CSS Config

Tailwind v4: Oxide Rust Engine, 182x Incremental Builds, CSS Config

Tailwind CSS v4 uses Rust-powered Oxide, moves config to CSS @theme directives, and builds 5x faster. Update utilities and convert config to CSS.

SQLite at the Edge: 100x Faster Reads, Cloudflare D1 and LiteFS

SQLite at the Edge: 100x Faster Reads, Cloudflare D1 and LiteFS

SQLite at the edge: sub-millisecond queries in serverless, CDN environments. Cloudflare D1, Turso, and Litestream distribute databases for production.

Like what you read?

Get new posts on Linux, AI, and self-hosting delivered to your inbox weekly.

Privacy Policy  ·  Terms of Service
2026 Botmonster