Skip to main content

baseAnything

What

A library for encoding integers into a series of symbols. The symbols can be anything. And it decodes too, of course.

Testing

Run pytest (configured in pyproject.toml; it collects the doctests in src/).

Howto

Install it (eg pip install baseAnything), and then from baseAnything import baseX. Examples, from the doctests:

Basic use

>>> bxbinary = baseX('01')  # Instantiates a baseX object with a Base-2 aka binary string-symbol alphabet
>>> bxbinary % 7
'111'

Proof: A roundtrip

>>> bxhexadecimal = baseX('0123456789ABCDEF')  # Base-16 aka hexadecimal
>>> 9000 == int(bxhexadecimal % 9000, base=16)
True

Arbitrary symbols

One can use arbitrary symbols. Anything. ['bla', 2, object(), object()] is a valid symbol alphabet.

It may be desirable to get a symbol list back rather than a string, so that the symbol framing is kept intact — because, for instance, a symbol alphabet of ['a', 'aa'] yields ambiguity in its output when it's mashed into a string; 'aaa' has 3 possible interpretations.

The % operator yields strings when encoding an integer. The / operator makes a baseX object return the encoding as a list of symbols instead.

>>> bxfunky = baseX(['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Ti'])
>>> bxfunky % 10  # Emits a warning, because the result may not be decodable!
'ReFa'
>>> bxfunky / 10  # Symbols returned as a list rather than concatenated into a string.
['Re', 'Fa']
>>> 10 == bxfunky / (bxfunky / 10)
True

Bizarre encodings

Speaking of arbitrary symbols... how about this visually compact encoding:

>>> bxbizarre = baseX(list(map(chr, range(0x0300, 0x036f))))  # unicode diacritical marks
>>> wut = 'O' + bxbizarre % 1234567890
>>> wut
'Ơ̡͎̈̎'
>>> bxbizarre / wut[1:]
1234567890

I don't like the operator overloading interface

Then use baseX.decode(input: Sequence) and baseX.encode(num: int).

Metadata

Release files for baseAnything 0.1.1

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

Source distribution (sdist)

Source distribution for baseAnything 0.1.1
File Size Uploaded Provenance Actions
baseanything-0.1.1.tar.gz 9.5 kB Without provenance Details for baseanything-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for baseAnything 0.1.1
File Interpreter ABI Platform Actions
baseanything-0.1.1-py3-none-any.whl Python 3 none any Details for baseanything-0.1.1-py3-none-any.whl

Total release size: 19.7 kB

Release files / baseanything-0.1.1.tar.gz

Download URL baseanything-0.1.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bfc9adf1de111bafbee62a766cfc4b9daf72b07b744cd167a1966f11d2250dba
BLAKE2b-256 checksum
How to use checksums
e3ce13ba92b8726c494514f4ab3f1f65a1b30159532502ff73496d88b7cb19de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / baseanything-0.1.1-py3-none-any.whl

Download URL baseanything-0.1.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f712506eef6dd4da6ebff1c300084f4fadca945ffab88fec3f3ecabd57b96899
BLAKE2b-256 checksum
How to use checksums
62bf167d843282ec853a480c0c22fbfc5cd26a4abe365bed1c522357b013b2e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for baseAnything 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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