base62

URL-safe base62 encoding and decoding for integers and byte data in Python

Library
PyPI
v1.0.0
81stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
29/100Needs Attention
Development Activity4
Maintenance0
Community40
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture70
Code Quality74
Innovation66
Learning Curve92

pybase62 is a small, focused Python module for base62 encoding, a URL-safe representation that uses only the characters 0-9, A-Z, and a-z. It converts integers and arbitrary byte data into compact strings and back, avoiding the special characters that can cause problems in URLs and identifiers.

Base62 strings are shorter than hexadecimal and safe to drop into URLs, filenames, and human-facing IDs without escaping. The library offers a minimal API for encoding and decoding both numbers and raw bytes, with an optional custom character set.

What You Get

  • Encoding and decoding of integers to and from base62 strings
  • Encoding and decoding of arbitrary byte data
  • A URL-safe alphabet (0-9, A-Z, a-z) with no special characters
  • Support for a custom character set / alphabet
  • A tiny, dependency-free single-module implementation

Common Use Cases

  • Shortening numeric database IDs into compact, URL-safe strings
  • Building short-link slugs from integer identifiers
  • Producing readable tokens or codes from binary data
  • Compressing UUIDs or hashes into shorter representations

Under The Hood

Architecture - The entire implementation is a single module, base62.py, exposing encode/decode functions for integers plus encodebytes/decodebytes for raw byte data. Encoding repeatedly divides by the base (62) against a character map, with an optional custom alphabet parameter; byte handling converts data to a big integer before encoding.

Tech Stack - Pure Python with no runtime dependencies, packaged via a classic setup.py. Distribution name is pybase62 while the import name is base62.

Code Quality - The repo ships a tests/ directory and a CHANGELOG; the module is tiny and self-contained, which keeps it easy to audit, though recent maintenance activity is minimal.

API Design - The API is minimal and intuitive: encode(n) / decode(s) for numbers and encodebytes/decodebytes for binary, with sensible defaults and an optional character-set override. There is essentially no boilerplate to get started.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search