philiprehberger-string-truncate
Truncate strings intelligently without cutting words.
Installation
pip install philiprehberger-string-truncate
Usage
from philiprehberger_string_truncate import truncate, truncate_middle, truncate_path
truncate("Hello beautiful world", max_length=15)
# "Hello…"
truncate("Hello beautiful world", max_length=15, suffix="...")
# "Hello..."
truncate_middle("Hello beautiful world of code", max_length=20)
# "Hello bea…l of code"
truncate_path("/very/long/path/to/some/file.txt", max_length=25)
# "/very/long/.../file.txt"
Word-count truncation
from philiprehberger_string_truncate import truncate_words
truncate_words("one two three four five", max_words=3)
# "one two three..."
truncate_words("one two", max_words=5)
# "one two"
Wrapping
from philiprehberger_string_truncate import wrap
wrap("the quick brown fox jumps over the lazy dog", width=20)
# "the quick brown fox\njumps over the lazy\ndog"
wrap("first paragraph\n\nsecond paragraph", width=80)
# "first paragraph\n\nsecond paragraph"
API
| Function / Class | Description |
|---|---|
truncate(text, max_length, suffix="…", break_words=False) |
Word-boundary truncation |
truncate_middle(text, max_length, separator="…") |
Keep start and end |
truncate_path(path, max_length, separator="/", placeholder="...") |
Path-aware truncation |
truncate_words(text, max_words, suffix="...") |
Truncate to a word count, appending suffix when shortened |
wrap(text, width=80) |
Wrap to lines at word boundaries; preserves paragraph breaks |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-string-truncate 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_string_truncate-0.2.0.tar.gz | 177.7 kB | Without provenance | Details for philiprehberger_string_truncate-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_string_truncate-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_string_truncate-0.2.0-py3-none-any.whl |
Total release size: 182.8 kB
Release files / philiprehberger_string_truncate-0.2.0.tar.gz
| Download URL | philiprehberger_string_truncate-0.2.0.tar.gz |
|---|---|
| Size | 177.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ee39487a30bb9bce8fa998c8a0e6d96d4c7769694b363aea403cef6b6e7bf25
|
|
BLAKE2b-256 checksum How to use checksums |
12edaae1bc0ce16d40b1eaf6e5eca27766ce1b1fc971de9df8a876487b553484
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_string_truncate-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_string_truncate-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd65cc2a10ec8cb5e8097fd0deadcb59597c0f914ae889513d100f6936a73e9a
|
|
BLAKE2b-256 checksum How to use checksums |
9ede37ac8af1d8af2a8d60072a727ec18eee2859590bdd7e235db99d051bcb57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-string-truncate 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.