Swopy
A library for biredirectional conversion between numeral systems. Supports 46 different systems across all numeral systems available in Unicode.
Supported Numeral Systems
- Aramaic:
Hatran, supporting integers between 1 and 999ImperialAramaic, supporting integers between 1 and 99,999Palmyrene, supporting integers between 1 and 99
- Brahmi:
Brahmi, supporting integers between 1 and 9,999
- Brahmi-Dravidian:
Grantha, supporting integers between 0 and infinity (base-7 positional)Saurashtra, supporting integers between 0 and infinityTamil, supporting integers between 1 and 9,999
- Brahmi-Gupta:
Bhaiksuki, supporting integers between 1 and 999SinhalaArchaic, supporting integers between 1 and 9,999
- Brahmi-Tai:
Ahom, supporting integers between 0 and infinity
- Cuneiform:
Cuneiform, supporting integers between 1 and 999
- Egyptian:
Egyptian, supporting integers between 1 and 1,000,000/manyCopticEpact, supporting integers between 1 and 9,999
- Ethiopic:
Ethiopic, supporting integers between 1 and 99,999,999
- Greek:
Aegean, supporting integers between 1 and 99,999Alphabetic, supporting integers between 1 and 9,999Attic, supporting integers and base-4 fractions between 1/4 and 99,999Etruscan, supporting integers between 1 and 399Milesian, supporting integers between 1 and 9,999
- Hebrew:
Hebrew, supporting integers between 1 and 9,999
- Hindu-Arabic:
Arabic, supporting integers, floats and fractions between-math.infandmath.inf. Also available inarabic.ArabicBakhshali, supporting integers between 1 and 9,999
- Kaktovik:
Kaktovik, supporting integers between -infinity and +infinity
- Kharosthi:
Kharosthi, supporting integers between 1 and 9,999
- Mayan:
Mayan, supporting integers between 0 and infinity
- Medefaidrin:
Medefaidrin, supporting integers between 0 and infinity (base-20 positional)
- Nabataean:
Nabataean, supporting integers between 1 and 999
- Numeric Systems:
CountingRod, supporting integers between 1 and 99
- Pahlavi:
InscriptionalParthian, supporting integers between 1 and 9,999InscriptionalPahlavi, supporting integers between 1 and 9,999PsalterPahlavi, supporting integers between 1 and 999
- Phoenician:
Phoenician, supporting integers between 1 and 999
- Roman, in the forms:
Early, supporting integers between 1 and 899Standard, supporting integers and base-12 fractions between 1/12 and 3,999Apostrophus, supporting integers between 1 and 100,000
- Sino-Tibetan:
Chinese, supporting integers between 1 and 99,999,999Khitan, supporting integers between 1 and 99,999,999Suzhou, supporting integers between 0 and infinityTangut, supporting integers between 1 and 99,999,999
- Siyaq:
IndicSiyaq, supporting integers between 1 and 99,999OttomanSiyaq, supporting integers between 1 and 99,999
- Sogdian:
Manichaean, supporting integers between 1 and 999OldSogdian, supporting integers between 1 and 999Sogdian, supporting integers between 1 and 999
- South Arabian:
AncientNorthArabian, supporting integers between 1 and 99AncientSouthArabian, supporting integers between 1 and 99,999
Installation
Install the package:
pip install swopy # or
uv add swopy
Usage
Basic Conversion
import swopy
from swopy import systems
# Convert integer Roman numeral to Egyptian hieroglyphic
swopy.swop('IX', systems.roman.Standard, systems.egyptian.Egyptian)
# '𓏺𓏺𓏺𓏺𓏺𓏺𓏺𓏺𓏺'
# Convert Apostrophus to an Arabic integer
swopy.swop('IↃI', systems.roman.Apostrophus, systems.arabic.Arabic)
# 501
Available Systems
import swopy
import pprint
systems = swopy.get_all_systems()
pprint.pprint(systems)
#{'arabic.Arabic': <class 'swopy.systems.arabic.Arabic'>,
# 'egyptian.Egyptian': <class 'swopy.systems.egyptian.Egyptian'>,
# 'etruscan.Etruscan': <class 'swopy.systems.etruscan.Etruscan'>,
# 'greek.Milesian': <class 'swopy.systems.greek.Milesian'>,
# 'roman.Apostrophus': <class 'swopy.systems.roman.Apostrophus'>,
# 'roman.Early': <class 'swopy.systems.roman.Early'>,
# 'roman.Standard': <class 'swopy.systems.roman.Standard'>
# ...}
swopy.swop(42, systems['arabic.Arabic'], systems['roman.Early'])
# 'XLII'
Error Handling
Swopy will raise a ValueError if there is a number is not representable in a numeral system
import swopy
from swopy import systems
swopy.swop(4000, systems.arabic.Arabic, systems.roman.Standard)
# ValueError: Number must be less than or equal to 3999.
systems.roman.Early.to_numeral(900)
# ValueError: Number must be less than or equal to 899.
or if a numeral is invalid
import swopy
from swopy import systems
swopy.swop('IIIII', systems.egyptian.Egyptian, systems.roman.Early)
# ValueError: Invalid Egyptian hieroglyph: I
systems.roman.Apostrophus.from_numeral('P')
# ValueError: Invalid Apostrophus characters at position 0
and will raise a TypeError if a numeral is not representable in a system.
import swopy
from swopy import systems
swopy.swop(1.2, systems.arabic.Arabic, systems.roman.Early)
# TypeError: 1.2 of type float cannot be represented in Early.
swopy.swop('I', systems.arabic.Arabic, systems.roman.Early)
# TypeError: I of type str cannot be represented in Arabic.
systems.egyptian.Egyptian.to_numeral(10.1)
# TypeError: 10.1 of type float cannot be represented in Egyptian.
Requirements
Swopy only relies on the standard library and needs Python 3.13 or higher. Swopy is currently tested on the latest versions of Windows, MacOS and Ubuntu for Python versions 3.13, 3.14.0, 3.14.3, and 3.15.
Development
Dependencies
Development dependencies are managed through pyproject.toml:
# Install development dependencies
sh scripts/startup.sh
Dev tools include:
- pytest / pytest-cov: Testing framework
- ruff: Fast Python linter and formatter
- pyright: Static type checker
- deptry: Dependency validation
- hypothesis: Property-based testing
- pre-commit: Git hooks framework
- tox, with tox-uv: Test runner
- uv
Metadata
Release files for swopy 0.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swopy-0.1.15.tar.gz | 124.2 kB | Without provenance | Details for swopy-0.1.15.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swopy-0.1.15-py3-none-any.whl | Python 3 | none | any | Details for swopy-0.1.15-py3-none-any.whl |
Total release size: 225.5 kB
Release files / swopy-0.1.15.tar.gz
| Download URL | swopy-0.1.15.tar.gz |
|---|---|
| Size | 124.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b7cb35ef95721af13c18677e460a9d4b7fb5490eae0d59bf467655da160a271
|
|
BLAKE2b-256 checksum How to use checksums |
bf8d8caa93471a171febb0f8f5cfc06940963d1dac9f8f4073f3a62dbbc34d88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swopy-0.1.15-py3-none-any.whl
| Download URL | swopy-0.1.15-py3-none-any.whl |
|---|---|
| Size | 101.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
734dc51d738d2dcc73cf996e724608a6aafd3a17192661bdea1c095399bf2c32
|
|
BLAKE2b-256 checksum How to use checksums |
fa9ff651b4a9280660fab972f092b6a4122a543d6979a389e356a18e246816b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swopy 0.1.15
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.