Skip to main content

A collection of numeral system converters.

Project description

Swopy

A Python library for converting between different numeral systems.

Overview

Swopy provides a simple and extensible interface to convert numbers between various numeral systems, including Roman numerals and Egyptian hieroglyphic numerals. The library supports bidirectional conversion—you can convert from any supported system to any other.

Supported Numeral Systems

  • Roman, in the forms
  • Early, supporting integers between 1 and 899
  • Standard, supporting integers between 1 and 3,999
  • Apostrophus, supporting integers between 1 and 100,000
  • Egyptian, supporting integers between 1 and 1,000,000/many
  • Arabic, supporting integers between -int(sys.float_info.max) and int(sys.float_info.max)

Installation

Install the package:

pip install swopy # or
uv add swopy

Usage

Basic Conversion

from swopy import Swopy, systems

converter = Swopy()

# Convert integer Roman numeral to Egyptian hieroglyphic
converter.convert('IX', systems.roman.Standard, systems.egyptian.Egyptian)
# '𓏺𓏺𓏺𓏺𓏺𓏺𓏺𓏺𓏺'

# Convert Apostrophus to an Arabic integer
converter.convert('IↃI', systems.roman.Apostrophus, systems.arabic.Arabic)
# 501

Available Systems

from swopy import Swopy, get_all_systems
import pprint
systems = get_all_systems()
pprint.pprint(systems)
#{'arabic.Arabic': <class 'swopy.systems.arabic.Arabic'>,
# 'egyptian.Egyptian': <class 'swopy.systems.egyptian.Egyptian'>,
# 'roman.Apostrophus': <class 'swopy.systems.roman.Apostrophus'>,
# 'roman.Early': <class 'swopy.systems.roman.Early'>,
# 'roman.Standard': <class 'swopy.systems.roman.Standard'>}

converter = Swopy()
converter.convert(42, systems['arabic.Arabic'], systems['roman.Early'])
# 'XLII'

Error Handling

The library validates numbers against the acceptable range for each system:

from swopy import Swopy, systems

converter = Swopy()

# This will raise ValueError (4000 is outside the valid range)
try:
    result = converter.convert(4000, systems.arabic.Arabic, systems.roman.Standard)
except ValueError as e:
    print(f"Conversion failed: {e}")
# Conversion failed: Number must be less than or equal to 3999.

Requirements

  • Python 3.13 or higher

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

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

swopy-0.1.1.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

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

swopy-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file swopy-0.1.1.tar.gz.

File metadata

  • Download URL: swopy-0.1.1.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","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}

File hashes

Hashes for swopy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 abe03fe05dbc33d38989174ed2818abd1be2d38faea05387e7155396bb29f667
MD5 c29de2bf79efecc950edb223954db76b
BLAKE2b-256 05513e5126e69a66531b993c3198b1b547165a2c9f77957c7837b67d05b48193

See more details on using hashes here.

File details

Details for the file swopy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: swopy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","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}

File hashes

Hashes for swopy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f0611cb810d04d9e51004a4f0791cc765eca8793e03b8d5abd96f95119594a1
MD5 872d049d8764bee549f8479b257020a1
BLAKE2b-256 d9e770f33e9445355b5084e67ba7087d177137ab4658404dfed3951e4776bc2d

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