textutils-nabil184 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
textutils/__init__.py ADDED
@@ -0,0 +1,13 @@
1
+ """A lightweight Python library for text processing."""
2
+
3
+ from .casing import capitalize_words
4
+ from .counting import character_count, word_count, word_frequency
5
+ from .transform import reverse
6
+
7
+ __all__ = [
8
+ "word_count",
9
+ "character_count",
10
+ "reverse",
11
+ "capitalize_words",
12
+ "word_frequency",
13
+ ]
@@ -0,0 +1,5 @@
1
+ """Text capitalization utilities."""
2
+
3
+ from ._capitalize import capitalize_words
4
+
5
+ __all__ = ["capitalize_words"]
@@ -0,0 +1,23 @@
1
+ def capitalize_words(text: str) -> str:
2
+ """Capitalize the first letter of each word.
3
+
4
+ Parameters
5
+ ----------
6
+ text : str
7
+ The input text.
8
+
9
+ Returns
10
+ -------
11
+ str
12
+ Text with each word capitalized.
13
+
14
+ Examples
15
+ --------
16
+ >>> capitalize_words("hello world")
17
+ 'Hello World'
18
+ >>> capitalize_words("hello open source")
19
+ 'Hello Open Source'
20
+ >>> capitalize_words("")
21
+ ''
22
+ """
23
+ return text.title()
@@ -0,0 +1,6 @@
1
+ """Word and character counting utilities."""
2
+
3
+ from ._count import character_count, word_count
4
+ from ._frequency import word_frequency
5
+
6
+ __all__ = ["word_count", "character_count", "word_frequency"]
@@ -0,0 +1,44 @@
1
+ def word_count(text: str) -> int:
2
+ """Count the number of words in a text.
3
+
4
+ Parameters
5
+ ----------
6
+ text : str
7
+ The input text.
8
+
9
+ Returns
10
+ -------
11
+ int
12
+ Number of words in the text.
13
+
14
+ Examples
15
+ --------
16
+ >>> word_count("Hello Open Source")
17
+ 3
18
+ >>> word_count("")
19
+ 0
20
+ """
21
+ return len(text.split())
22
+
23
+
24
+ def character_count(text: str) -> int:
25
+ """Count the number of characters in a text.
26
+
27
+ Parameters
28
+ ----------
29
+ text : str
30
+ The input text.
31
+
32
+ Returns
33
+ -------
34
+ int
35
+ Number of characters, including spaces.
36
+
37
+ Examples
38
+ --------
39
+ >>> character_count("Hello")
40
+ 5
41
+ >>> character_count("Hello World")
42
+ 11
43
+ """
44
+ return len(text)
@@ -0,0 +1,59 @@
1
+ """Utilities for counting word frequencies.
2
+
3
+ Original implementation inspired by:
4
+ https://www.geeksforgeeks.org/python/find-frequency-of-each-word-in-a-string-in-python/
5
+ """
6
+
7
+ import re
8
+ from collections import Counter
9
+
10
+
11
+ def word_frequency(s: str) -> dict[str, int]:
12
+ """Count the frequency of each word in a text.
13
+
14
+ The comparison is case-insensitive and punctuation is ignored.
15
+
16
+ Parameters
17
+ ----------
18
+ s : str
19
+ The input text.
20
+
21
+ Returns
22
+ -------
23
+ dict[str, int]
24
+ A dictionary containing each word and its frequency.
25
+
26
+ Raises
27
+ ------
28
+ TypeError
29
+ If the input is not a string.
30
+
31
+ Examples
32
+ --------
33
+ >>> word_frequency("Hello hello world!")
34
+ {'hello': 2, 'world': 1}
35
+ >>> word_frequency("")
36
+ {}
37
+ """
38
+ if not isinstance(s, str):
39
+ raise TypeError("Input must be a string")
40
+
41
+ words = s.split()
42
+
43
+ cleaned_words = []
44
+ for word in words:
45
+ cleaned_words.extend(re.findall(r"\b\w+\b", word.casefold()))
46
+
47
+ words = cleaned_words
48
+ freq = Counter(words)
49
+
50
+ result = {}
51
+ for w, c in freq.items():
52
+ result[w] = c
53
+
54
+ return result
55
+
56
+
57
+ # Usage example
58
+ if __name__ == "__main__":
59
+ print(word_frequency("hello hello there"))
@@ -0,0 +1,5 @@
1
+ """Text transformation utilities."""
2
+
3
+ from ._reverse import reverse
4
+
5
+ __all__ = ["reverse"]
@@ -0,0 +1,21 @@
1
+ def reverse(text: str) -> str:
2
+ """Reverse the characters in a text.
3
+
4
+ Parameters
5
+ ----------
6
+ text : str
7
+ The input text.
8
+
9
+ Returns
10
+ -------
11
+ str
12
+ Text with its characters in reverse order.
13
+
14
+ Examples
15
+ --------
16
+ >>> reverse("Hello")
17
+ 'olleH'
18
+ >>> reverse("")
19
+ ''
20
+ """
21
+ return text[::-1]
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: textutils-nabil184
3
+ Version: 0.2.1
4
+ Summary: A lightweight Python library for common text-processing operations.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/nabil184/textutils
7
+ Project-URL: Repository, https://github.com/nabil184/textutils
8
+ Project-URL: Issues, https://github.com/nabil184/textutils/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest<10,>=8; extra == "dev"
14
+ Requires-Dist: pytest-cov<8,>=5; extra == "dev"
15
+ Requires-Dist: black==25.1.0; extra == "dev"
16
+ Requires-Dist: ruff==0.9.7; extra == "dev"
17
+ Requires-Dist: pre-commit<5,>=3; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+
21
+ # textutils
22
+
23
+ `textutils` is a lightweight Python library providing simple
24
+ utilities for common text-processing operations.
25
+
26
+ ## Features
27
+
28
+ The library currently provides:
29
+
30
+ - `word_count(text)` - Count the number of words in a text.
31
+ - `character_count(text)` - Count the number of characters.
32
+ - `reverse(text)` - Reverse a text.
33
+ - `capitalize_words(text)` - Capitalize each word.
34
+ - `word_frequency(text)` - Count how often each word appears.
35
+
36
+ ## Installation
37
+
38
+ Requires Python 3.10 or newer.
39
+
40
+ After the first PyPI release is published, install the package with:
41
+
42
+ ```bash
43
+ python -m pip install textutils-nabil184
44
+ ```
45
+
46
+ The distribution name on PyPI is `textutils-nabil184`,
47
+ while the Python import name remains `textutils`.
48
+
49
+ ## Usage
50
+
51
+ ```python
52
+ from textutils import (
53
+ word_count,
54
+ character_count,
55
+ reverse,
56
+ capitalize_words,
57
+ word_frequency,
58
+ )
59
+
60
+ text = "hello open source"
61
+
62
+ print(word_count(text))
63
+ print(character_count(text))
64
+ print(reverse(text))
65
+ print(capitalize_words(text))
66
+ print(word_frequency("Hello hello world!"))
67
+ ```
68
+
69
+ Expected output:
70
+
71
+ ```text
72
+ 3
73
+ 17
74
+ ecruos nepo olleh
75
+ Hello Open Source
76
+ {'hello': 2, 'world': 1}
77
+ ```
78
+
79
+ ## Development
80
+
81
+ Clone the repository and install the package with its development dependencies:
82
+
83
+ ```bash
84
+ git clone https://github.com/nabil184/textutils.git
85
+ cd textutils
86
+ python -m pip install -e ".[dev]"
87
+ ```
88
+
89
+ ### Running tests
90
+
91
+ Run the complete test suite:
92
+
93
+ ```bash
94
+ python -m pytest -v
95
+ ```
96
+
97
+ Run tests with coverage:
98
+
99
+ ```bash
100
+ python -m pytest --cov=textutils --cov-branch --cov-report=term-missing
101
+ ```
102
+
103
+ Tests are organized inside each subpackage, close to the corresponding implementation.
104
+
105
+ ### Code quality
106
+
107
+ Format the project with Black:
108
+
109
+ ```bash
110
+ python -m black .
111
+ ```
112
+
113
+ Check formatting without modifying files:
114
+
115
+ ```bash
116
+ python -m black --check .
117
+ ```
118
+
119
+ Check code quality with Ruff:
120
+
121
+ ```bash
122
+ python -m ruff check .
123
+ ```
124
+
125
+ ## Continuous Integration
126
+
127
+ This project uses GitHub Actions to automatically check
128
+ code quality and run the test suite.
129
+
130
+ The CI workflow runs on Pull Requests targeting `main`
131
+ and on pushes to `main`.
132
+
133
+ Four environments are tested:
134
+
135
+ - Ubuntu 22.04 with Python 3.11
136
+ - Ubuntu 22.04 with Python 3.12
137
+ - macOS 15 with Python 3.11
138
+ - macOS 15 with Python 3.12
139
+
140
+ Each CI job installs the project, checks Black and Ruff,
141
+ and executes pytest.
142
+
143
+ ## Pre-commit
144
+
145
+ The project uses pre-commit to run Black and Ruff
146
+ automatically before commits.
147
+
148
+ Install the development dependencies:
149
+
150
+ ```bash
151
+ python -m pip install -e ".[dev]"
152
+ ```
153
+
154
+ Install the Git hook:
155
+
156
+ ```bash
157
+ python -m pre_commit install
158
+ ```
159
+
160
+ Run all hooks manually:
161
+
162
+ ```bash
163
+ python -m pre_commit run --all-files
164
+ ```
165
+
166
+ ## Contributing
167
+
168
+ Contributions are welcome.
169
+
170
+ To contribute, create a branch, make your changes,
171
+ run the tests and open a Pull Request.
172
+
173
+ Please ensure that tests pass and that Black and Ruff
174
+ report no issues before submitting your changes.
175
+
176
+ ## License
177
+
178
+ This project is licensed under the MIT License.
179
+ See the `LICENSE` file for details.
@@ -0,0 +1,13 @@
1
+ textutils/__init__.py,sha256=J_D-On4eSBXxdA3hiHCkdV5KbcccMeAc76ZxGRNmFwA,308
2
+ textutils/casing/__init__.py,sha256=HclnwhnQ51_GsIAuESMH2thPGrhGoAm9YX6xKU_oR8k,112
3
+ textutils/casing/_capitalize.py,sha256=QkvQullObx4omYLAd9oY2nueipE6evaNg_t4byK5LRA,456
4
+ textutils/counting/__init__.py,sha256=OfRTwjRZ3PEZ9BVd1DZ84yNrIGcQB_yZNxxPrPctw10,196
5
+ textutils/counting/_count.py,sha256=XiqSvmDwYUnnLbZDpIJmNo6Ctzl_eGU83txskZASRYs,739
6
+ textutils/counting/_frequency.py,sha256=TsYxBatJv5iTZ_M2ssM2GL4NsDni3LYr1tpzDsI1V_Y,1228
7
+ textutils/transform/__init__.py,sha256=Oru74s2ag7iSW7-bdIdAf3yaF_reMgrwx9CocsJJBvo,91
8
+ textutils/transform/_reverse.py,sha256=b_yqRLCKURL4XOepTzPbVUEgoIE6vEdMDy3XD0XOH1c,347
9
+ textutils_nabil184-0.2.1.dist-info/licenses/LICENSE,sha256=Hi_qIjtzkT7OSK5OVGpiUkpgthb-W5pyM2Uk4TMUcoA,1069
10
+ textutils_nabil184-0.2.1.dist-info/METADATA,sha256=rkVjt9GSAGQXZVafgJhJAh1DL0brZdEC2wIcOBe6gEg,3659
11
+ textutils_nabil184-0.2.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
12
+ textutils_nabil184-0.2.1.dist-info/top_level.txt,sha256=amWgGsYwaWzVol7zPaWIjxj2Of6hEptj7rE9MR3bp_E,10
13
+ textutils_nabil184-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NABIL DAHMANI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ textutils