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.3.tar.gz (5.5 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.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ispunct-1.0.3.tar.gz
  • Upload date:
  • Size: 5.5 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.3.tar.gz
Algorithm Hash digest
SHA256 8dfb2d3a6001b2f0e8b007036ba5be085dcfce6e054e696eb44e2001a3bf9343
MD5 ac678e65684eaae923d678022b3b0cca
BLAKE2b-256 a8f1fc03175bd04ff9cb7e4804a663f5efd1a561c9214e57990885e260041030

See more details on using hashes here.

Provenance

The following attestation bundles were made for ispunct-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: ispunct-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f865d4731a7cb742bfab2ed70aa8d99ba77c73a245b4f2be918e9f35bda2e60
MD5 3e9213417c5b7a296cc2d7ec2dc1d43a
BLAKE2b-256 cad6c1b6eb05b783d804be10b1f783108cd5e417ba15773df1cf030ad1263cc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ispunct-1.0.3-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