Skip to main content

b62

PyPI version Python Version Total downloads License Build Status

Because the world desperately needed another Base62 library.

What 🤔

Converts integers to strings and back. Revolutionary stuff.

  • Uses Rust 🦀 (because Python is apparently too slow for basic arithmetic)
  • Zero dependencies (we're very proud of this achievement)
  • Type hints (for people who forgot what integers look like)

Install

pip install b62

Shocking, we know.

Usage

import b62

# Turn number into string
encoded = b62.encode(123456789)  # "8M0kX"

# Turn string back into number  
decoded = b62.decode("8M0kX")    # 123456789

# It throws errors when you give it garbage
try:
    b62.decode("not_base62!")
except ValueError:
    print("Surprise! Invalid input breaks things.")

Batch Operations

For when you have many numbers to convert:

# Encode multiple integers (in parallel, because waiting is hard)
encoded = b62.encode_batch([1, 62, 123456789])  # ['1', '10', '8M0kX']

# Decode multiple strings (also in parallel)
decoded = b62.decode_batch(['1', '10', '8M0kX'])  # [1, 62, 123456789]

Performance ⚡

It's fast. Here are some numbers to make you feel better about your life choices:

  • Decode: ~52ns per operation (congratulations, you saved nanoseconds)
  • Encode: ~90ns per operation (your URL shortener will thank you)
  • Batch operations: Uses all your CPU cores (because why not)

Benchmarks run on a machine that probably costs more than your car. 💸

API

encode(num: int) -> str

Converts integer to Base62 string. Rocket science.

decode(string: str) -> int

Converts Base62 string back to integer. PhD not required.

encode_batch(nums: list[int]) -> list[str]

Like encode() but for people with lists.

decode_batch(strings: list[str]) -> list[int]

Like decode() but for people with more lists.

Character Set

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Yes, we counted. There are 62 of them.

Use Cases

  • URL shortening (because long URLs hurt feelings)
  • Database ID obfuscation (security through obscurity, naturally)
  • Compact serialization (for when JSON is "too verbose")
  • Impressing coworkers with Rust integration

Development

make test    # Run tests (they probably pass)
make ci      # Pretend you care about CI
make build   # Build the thing

License

MIT - Because we're not monsters. 😇


Now go forth and encode responsibly.

Metadata

Release files for b62 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for b62 1.1.5
File
b62-1.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
b62-1.1.5-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
b62-1.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
b62-1.1.5-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
b62-1.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
b62-1.1.5-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 1.8 MB

Release files / b62-1.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL b62-1.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 328.5 kB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d12e39193e7a95abda39e66c77c346fed79d368bee09f0fbba638c3aa6a4723b
BLAKE2b-256 checksum
How to use checksums
eca50117a1f0aef6cfc276e38041eec747f652ef5aa1fb358bdcb86d638562c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / b62-1.1.5-cp314-cp314-macosx_11_0_arm64.whl

Download URL b62-1.1.5-cp314-cp314-macosx_11_0_arm64.whl
Size 281.7 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6bee4374dce5f9cb642cadfec7229135b52710e62baa7b68d8afb87ca52525de
BLAKE2b-256 checksum
How to use checksums
a1c87b9d386d32bd2166207cf582ac71685434c3fa68f2e4e3294f32816e4768
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / b62-1.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL b62-1.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 328.5 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a6eb96b7057c18a327984e0ea5a621896cd03d122512a58553fed3a9021591d2
BLAKE2b-256 checksum
How to use checksums
465aca2898a46dc71ce559e89f0592416a1cdd6b8e5eca9c5889f3c97a86ac96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / b62-1.1.5-cp313-cp313-macosx_11_0_arm64.whl

Download URL b62-1.1.5-cp313-cp313-macosx_11_0_arm64.whl
Size 281.7 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d79778719f214d402e49d802545e0bdbaaae6ff4c2f02c6cb188e18f705926fc
BLAKE2b-256 checksum
How to use checksums
a2a5fc759227593029ea48e069c305be934b78a2d17228629b6440cae14a72bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / b62-1.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL b62-1.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 328.5 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4851db882a9436308bcec81ab22be27b340f8a63b4f2f40f6feb70ea4fe1eb3d
BLAKE2b-256 checksum
How to use checksums
3c59f9714c778a9ee1e18494f21891418700e4957b8e38453cc5f9a2c9af2b88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / b62-1.1.5-cp312-cp312-macosx_11_0_arm64.whl

Download URL b62-1.1.5-cp312-cp312-macosx_11_0_arm64.whl
Size 281.7 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d1fca63b1c8ee3a5a2d2831e1b48aa32430949789db4e69faf28c2a9cab4bc56
BLAKE2b-256 checksum
How to use checksums
7cd2a9652abaa124483722ac076c55b6f9161cc475a94f2f112fd979c2e1654d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.1.5 This release

6 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page