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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dfb2d3a6001b2f0e8b007036ba5be085dcfce6e054e696eb44e2001a3bf9343
|
|
| MD5 |
ac678e65684eaae923d678022b3b0cca
|
|
| BLAKE2b-256 |
a8f1fc03175bd04ff9cb7e4804a663f5efd1a561c9214e57990885e260041030
|
Provenance
The following attestation bundles were made for ispunct-1.0.3.tar.gz:
Publisher:
ci.yml on jakewilliami/ispunct-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ispunct-1.0.3.tar.gz -
Subject digest:
8dfb2d3a6001b2f0e8b007036ba5be085dcfce6e054e696eb44e2001a3bf9343 - Sigstore transparency entry: 799030513
- Sigstore integration time:
-
Permalink:
jakewilliami/ispunct-py@e7549cf1ed414a58bd8affc3cca064d4fb115bf7 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/jakewilliami
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@e7549cf1ed414a58bd8affc3cca064d4fb115bf7 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f865d4731a7cb742bfab2ed70aa8d99ba77c73a245b4f2be918e9f35bda2e60
|
|
| MD5 |
3e9213417c5b7a296cc2d7ec2dc1d43a
|
|
| BLAKE2b-256 |
cad6c1b6eb05b783d804be10b1f783108cd5e417ba15773df1cf030ad1263cc6
|
Provenance
The following attestation bundles were made for ispunct-1.0.3-py3-none-any.whl:
Publisher:
ci.yml on jakewilliami/ispunct-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ispunct-1.0.3-py3-none-any.whl -
Subject digest:
5f865d4731a7cb742bfab2ed70aa8d99ba77c73a245b4f2be918e9f35bda2e60 - Sigstore transparency entry: 799030517
- Sigstore integration time:
-
Permalink:
jakewilliami/ispunct-py@e7549cf1ed414a58bd8affc3cca064d4fb115bf7 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/jakewilliami
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@e7549cf1ed414a58bd8affc3cca064d4fb115bf7 -
Trigger Event:
push
-
Statement type: