Tidy(Py)String: Wrangle those Strings
Easier string operations in Python, inspired by the tidyverse (especially stringr).
All functions can be run both on single strings and vectors of strings, with direct support for base python's string type (str), lists or arrays of strings ([str, str, ...]), and Pandas columns / series (pd.Series), and indirect support other string-like or string-typed variables.
Quick Start
Install the package from PyPI:
pip install tidystring
Requirements:
- Python 3.9 or higher
- pandas 1.2.4 or higher
Then, wrangle those strings:
import pandas as pd
import tidystring as ts
strings = pd.Series(["text_alpha", "text_beta", "text_gamma"])
## detect if strings contain "alpha"
ts.str_detect(strings, "alpha")
## remove "alpha" from all strings
ts.str_remove(strings, "alpha")
## convert all strings to title case, removing dashes
ts.str_to_title(strings, remove_dashes=True)
Inspired by StringR
... which offers the following functions:
str_length()str_sub()str_dup()str_trim()str_pad()str_wrap()str_to_upper()str_to_lower()str_to_title()str_detect()str_count()str_locate()str_locate_all()str_extract()str_extract_all()str_match()str_match_all()str_replace()str_replace_all()str_split()str_split_fixed()str_glue()str_order()str_sort()str_subset()str_which()str_squish()str_flatten()
(All of these are on my to-do list, but for now...)
tidystring's currently available stringr ports:
str_detect()str_remove()str_extract()str_split()str_trim()str_to_title()str_to_upper()str_to_lower()
Additional tidystring functions not in stringr:
str_concatstr_startswithstr_endswithstr_upper_cutstr_search_applystr_search_recasestr_dash_to_space
Check out the documentation for more information.
Tidyverse-Inspired Python
There are increasingly a number of other Python packages that are helping to bring the beautiful tidyverse to Python. Here's a couple to consider:
Here's a short-list of some stand-outs:
Development Notes
Installation Options
Install the stable version from PyPI:
pip install tidystring
Or install the latest development version from GitHub:
pip install git+https://github.com/ColinConwell/TidyPyString.git
Code Formatting
If you're contributing to the project, you can use the provided formatting scripts:
# Format the code (modifies files)
./devops/run_format.sh
# Check code formatting (doesn't modify files)
./devops/run_linter.sh
Use of Generative AI
All code in this package has been tested by me (a human), but much of the documentation comes from a custom generative AI auto-documentation pipeline, powered by Claude-Sonnet-3.7. Documentation may thus be subject to some error. Please feel free to file an issue if this appears to be the case.
Metadata
Release files for tidystring 0.1.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 |
|---|---|---|---|---|
| tidystring-0.1.0.tar.gz | 12.6 kB | Without provenance | Details for tidystring-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tidystring-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tidystring-0.1.0-py3-none-any.whl |
Total release size: 26.3 kB
Release files / tidystring-0.1.0.tar.gz
| Download URL | tidystring-0.1.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89f154c3b84f0376cda649b348645a4febce1d4002baa1ae06d77e00a7a5b30f
|
|
BLAKE2b-256 checksum How to use checksums |
d8d6f2a618b42acd7b0cb653641a28d668589bda337c6d44890653d1cf58c084
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.9.21 Linux/6.8.0-1021-azure
|
Release files / tidystring-0.1.0-py3-none-any.whl
| Download URL | tidystring-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7bde3830fd0974be59bfde70fc4c2acf8eda2e286e9786ae48c87f1c7b4e99b
|
|
BLAKE2b-256 checksum How to use checksums |
bedd36aa0e60e0a0522327c54a06c6b4187ac60dbdc991c833e14cd5f16b73bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.9.21 Linux/6.8.0-1021-azure
|
Security for tidystring 0.1.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.