Skip to main content

Sepyrate is a lightweight Python library for formatting numbers with custom thousands and decimal separators.

Project description

Sepyrate

Sepyrate is a lightweight Python library for formatting numbers with custom thousands and decimal separators. It supports common delimiters such as commas (","), dots ("."), spaces (" "), and apostrophes ("'").

This library is particularly useful for localized currency formatting in web frameworks like Django or Flask, where you may need to display numbers according to regional standards (e.g., changing 12879.45 to 12.879,45 or 12 879.45).

(1) Installation

Use the package manager pip to install sepyrate:

pip install sepyrate

(2) Prerequisites

None.

(3) Usage

The primary function is digit_separation(). It accepts the following arguments:

  • amount: The value to format. Supports int, float, numpy.float32, numpy.float64, and decimal.Decimal.
  • tsep: The character to use as the thousands separator [str].
  • dsep (Optional): The character to use as the decimal separator [str]. Defaults to None (automatically inferred based on tsep).

The function returns string of digits.

(4) Supported Separator Combinations

Following Wikipedia standards:

tsep (Thousands) Supported dsep (Decimal)
Comma (,) .
Dot (.) , or '
Space ( ) , or .
Apostrophe (') , or .

Note: he Indian numbering system (e.g., 1,00,000) is not currently supported but is planned for a future release.

(5) Examples

To use, import the function:

from sepyrate import digit_separation

Formatting Floating-Point Numbers, numpy.float32, or numpy.float64:

amount = 1200.56 # or amount = np.float64(1200.56)

# Using a dot for thousands and a comma for decimals
print(digit_separation(amount, tsep='.', dsep=',')) # Output: '1.200,56'

# dsep is inferred as ',' if tsep is '.'
print(digit_separation(amount, tsep='.'))           # Output: '1.200,56'

Formatting Integers

value = 10000000

# Grouping by space without decimals
print(digit_separation(value, tsep=' '))            # Output: '10 000 000'
print(digit_separation(value, tsep='.'))            # Output: '10.000.000'

Django Usage

In models.py:

from django.db import models
from sepyrate import digit_separation


class Project(models.Model):
    name = models.CharField(max_length=100)
    budget = models.DecimalField(max_digits=15, decimal_places=2)
    ... # other fields

    def budget_display(self):
        """Returns the budget formatted with dot thousands and comma decimals."""
        return digit_separation(self.budget, tsep='.', dsep=',')

    # Optional: This allows the method to be used in the Django Admin 'list_display'
    budget_display.short_description = 'Formatted Budget'

In your Django template (e.g., project_detail.html)

<p>Total Budget: {{ project.budget_display }}</p>

Changelog / Version History

[1.1.0] - 2026-02-27

Added

  • Core digit_separation function support for numpy32, numpy64, and Decimal.

Changed

  • Internal logic for type conversion to improve precision.

  • Fixed a TypeError when passing Decimal objects with zero exponents.

[0.1.0] - 2024-07-08

  • Initial release of Sepyrate.

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

sepyrate-1.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

sepyrate-1.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file sepyrate-1.1.0.tar.gz.

File metadata

  • Download URL: sepyrate-1.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for sepyrate-1.1.0.tar.gz
Algorithm Hash digest
SHA256 99996b4ebe0c32ab5dbe2da61f8584d3a3528e3c0a95647a5a51ec2bc4cdd632
MD5 8c760eccbdae0c52536a45e413d20dce
BLAKE2b-256 c644f87ebf5a0bddec8d7bb5d5dbfedaf7ab414a1ba5092205b347947ff0939c

See more details on using hashes here.

File details

Details for the file sepyrate-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sepyrate-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for sepyrate-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f6987010b45cde6080037ac182de8ce907e0b924ff2330785134caae3e90269
MD5 76e2efbf5a9b3842f68dd98e3bce8f6f
BLAKE2b-256 d8e629cba1df292ca85d6ab06d7a56226fefe6ff1501b748bd5c4a89e82d2f56

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