Skip to main content

Implements Base1 (from qntm) in a python library

Project description

base1 (python implementation)

This is a python implementation of Base1 encoding, as detailed in https://github.com/qntm/base1. It follows that API. I implemented this largely on 2025-12-29, for fun.

Fun fact: this project has to be called "base-one" on pypi because "base1" is considered too similar to an existing project, "basel". https://stackoverflow.com/a/71490005

It is a python library, but you can also use it as a simple command-line utility as a bonus. Given a string input, the first argument to the command, it gives you the base1n of that data. (Internally, the program takes whatever python gives it as the string that "is" argv[1] and then calls .encode() directly on that to get a bytes. If you're having problems with complicated utf-8/other-encoding characters, that might be the culprit.)

Qntm's base1 works with javascript concepts, which have analogues in python. So, we use bytes instead of Uint8Array, and int instead of BigInt. The names of functions use snakecase instead of camelcase.

The algorithm to encode and decode base1, especially in closed form, is not entirely trivial if you just read qntm's readme. You can derive it, with some analytical work. It's all there, but you have to think about it a little. (What does it mean, mathematically or in terms of computer operations, to, eg, "sort all possible buffers by length and then lexicographically"? that seems like it would take a lot of time for the CPU to execute.) I purposefully did not read any of his code, so that I could use my own license instead of his. (And also to treat it as a fun riddle for a moment.) This software is public domain btw. Also, most of my test examples are just from his readme, which I'm treating as a standard (and also I'm treating those cases as non-copyrightable due to the concept-expression merger for math (don't worry about that)).

I lost interest in this project after completing it but before testing it very well. I mean, I guess I do test it pretty well, because those test cases are how I figured out what the heck I was doing, but I don't know about code coverage, test framework, CI, etc etc.

Since the important part of Base1 encoding is the length of the base1 string, various (but not all) parts of this program refer to that concept as a "base1n" (it's just an int holding the value of the length instead of the string that is that long). That's... you know, kind of the joke of this whole project, when you get right down to it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

base_one-1.0.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

base_one-1.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file base_one-1.0.2.tar.gz.

File metadata

  • Download URL: base_one-1.0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for base_one-1.0.2.tar.gz
Algorithm Hash digest
SHA256 cdf252f56d7445fe9cb0045daed58c3760e3d1fee5b31b4c4c213322d2f6d69b
MD5 d642e94287d517bb34e081307f6c9405
BLAKE2b-256 683d174f9b3517806aab181533bf12172a8b62efbd6c46f02e45bc12b69d8e2c

See more details on using hashes here.

File details

Details for the file base_one-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: base_one-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for base_one-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f1179863d20a40fa10952ee544686881e1460e456f4dd446242d01fe36ebb87
MD5 6c81c515ed18128a65d5fb141f9edad6
BLAKE2b-256 0a87c1fb6eb87543bf9b1ee7df4ba90e4c7805593e8c37c1f56f9ad3977c5724

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page