Skip to main content

Small Python library to check if a character is a punctuation character

Project description

ispunct

A small Python library for checking whether a character is a punctuation character.


Quick Start

from ispunct import ispunct

assert ispunct("?")
assert not ispunct("a")
assert ispunct("‽")

Using ispunct as a Library

This package is published on PyPI. You can install it with PIP:

$ pip add ispunct

Or, if using UV for dependency management:

$ uv add ispunct

History

The origin of this project comes from an equivalent function to Julia's ispunct, which is itself derived from the C implementation for obtaining a Unicode character's category code. This is a more complete solution than checking against string.punctuation or curses.ascii.ispunct. There is also a StackOverflow question for this functionality which I have answered.

Notes on Internal Functionality

This library also implements (and uses internally) bitwise functions to calculate the number of leading/trailing zeros/ones in the bitwise representation of a Python integer. We also compute a Python integer that has the same bitpattern as a given character (i.e., simulating Julia's bitcast). These are required in order to determine a character's category code.

Alternative Libraries

This was written mostly as a proof of concept using bitwise operations on character codes. You could derive similar functionality from the standard library unicodedata, or matching on character category with regex (see examples here).

A spiritual sister package and successor to ispunct is strip-marks, in which we further explore unicode operations in Python.

Citation

If your research depends on ispunct, please consider giving us a formal citation: citation.bib.

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

ispunct-1.0.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

ispunct-1.0.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file ispunct-1.0.4.tar.gz.

File metadata

  • Download URL: ispunct-1.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ispunct-1.0.4.tar.gz
Algorithm Hash digest
SHA256 f7c3a004e9022833cff1e51cf2ccb0e191061060b5d7e1fba6fbd6832f150157
MD5 143516cd4b3b4078802ef6d19cb4b1d8
BLAKE2b-256 4259c1fbbb70dbecf682d158d713ed64ba74a2c3ee765ef2a234726e87064d0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ispunct-1.0.4.tar.gz:

Publisher: ci.yml on jakewilliami/ispunct-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ispunct-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: ispunct-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ispunct-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9b7643dea572ae260daf4a7570844b3ab2cd38bc9cdfd5ecd83796114749f79e
MD5 03944734d02cc180e29ea1640cb81d9c
BLAKE2b-256 75db9db5db5855d846989b4b9b13fb3cd5c465a49fc2deb30eac89c6aaa34cfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ispunct-1.0.4-py3-none-any.whl:

Publisher: ci.yml on jakewilliami/ispunct-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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