Debian Codegraph @

third_party/python/python_slugify/python_slugify-8.0.4.dist-info/METADATA

raw
1 Metadata-Version: 2.1
2 Name: python-slugify
3 Version: 8.0.4
4 Summary: A Python slugify application that also handles Unicode
5 Home-page: https://github.com/un33k/python-slugify
6 Author: Val Neekman
7 Author-email: [email protected]
8 License: MIT
9 Classifier: Development Status :: 5 - Production/Stable
10 Classifier: Intended Audience :: Developers
11 Classifier: Natural Language :: English
12 Classifier: License :: OSI Approved :: MIT License
13 Classifier: Programming Language :: Python
14 Classifier: Programming Language :: Python :: 3
15 Classifier: Programming Language :: Python :: 3.7
16 Classifier: Programming Language :: Python :: 3.8
17 Classifier: Programming Language :: Python :: 3.9
18 Classifier: Programming Language :: Python :: 3.10
19 Classifier: Programming Language :: Python :: 3.11
20 Classifier: Programming Language :: Python :: 3.12
21 Requires-Python: >=3.7
22 Description-Content-Type: text/markdown
23 License-File: LICENSE
24 Requires-Dist: text-unidecode (>=1.3)
25 Provides-Extra: unidecode
26 Requires-Dist: Unidecode (>=1.1.1) ; extra == 'unidecode'
27
28 # Python Slugify
29
30 **A Python slugify application that handles unicode**.
31
32 [![status-image]][status-link]
33 [![version-image]][version-link]
34 [![coverage-image]][coverage-link]
35
36 # Overview
37
38 **Best attempt** to create slugs from unicode strings while keeping it **DRY**.
39
40 # Notice
41
42 This module, by default installs and uses [text-unidecode](https://github.com/kmike/text-unidecode) _(GPL & Perl Artistic)_ for its decoding needs.
43
44 However, there is an alternative decoding package called [Unidecode](https://github.com/avian2/unidecode) _(GPL)_. It can be installed as `python-slugify[unidecode]` for those who prefer it. `Unidecode` is believed to be more [advanced](https://github.com/un33k/python-slugify/wiki/Python-Slugify-Wiki#notes-on-unidecode).
45
46 ### `Official` Support Matrix
47
48 | Python | Slugify |
49 | -------------- | ------------------ |
50 | `>= 2.7 < 3.6` | `< 5.0.0` |
51 | `>= 3.6 < 3.7` | `>= 5.0.0 < 7.0.0` |
52 | `>= 3.7` | `>= 7.0.0` |
53
54 # How to install
55
56 easy_install python-slugify |OR| easy_install python-slugify[unidecode]
57 -- OR --
58 pip install python-slugify |OR| pip install python-slugify[unidecode]
59
60 # Options
61
62 ```python
63 def slugify(
64 text: str,
65 entities: bool = True,
66 decimal: bool = True,
67 hexadecimal: bool = True,
68 max_length: int = 0,
69 word_boundary: bool = False,
70 separator: str = DEFAULT_SEPARATOR,
71 save_order: bool = False,
72 stopwords: Iterable[str] = (),
73 regex_pattern: str | None = None,
74 lowercase: bool = True,
75 replacements: Iterable[Iterable[str]] = (),
76 allow_unicode: bool = False,
77 ) -> str:
78 """
79 Make a slug from the given text.
80 :param text (str): initial text
81 :param entities (bool): converts html entities to unicode (foo &amp; bar -> foo-bar)
82 :param decimal (bool): converts html decimal to unicode (&#381; -> Ž -> z)
83 :param hexadecimal (bool): converts html hexadecimal to unicode (&#x17D; -> Ž -> z)
84 :param max_length (int): output string length
85 :param word_boundary (bool): truncates to end of full words (length may be shorter than max_length)
86 :param save_order (bool): if parameter is True and max_length > 0 return whole words in the initial order
87 :param separator (str): separator between words
88 :param stopwords (iterable): words to discount
89 :param regex_pattern (str): regex pattern for disallowed characters
90 :param lowercase (bool): activate case sensitivity by setting it to False
91 :param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
92 :param allow_unicode (bool): allow unicode characters
93 :return (str): slugify text
94 """
95 ```
96
97 # How to use
98
99 ```python
100 from slugify import slugify
101
102 txt = "This is a test ---"
103 r = slugify(txt)
104 self.assertEqual(r, "this-is-a-test")
105
106 txt = '影師嗎'
107 r = slugify(txt)
108 self.assertEqual(r, "ying-shi-ma")
109
110 txt = '影師嗎'
111 r = slugify(txt, allow_unicode=True)
112 self.assertEqual(r, "影師嗎")
113
114 txt = 'C\'est déjà l\'été.'
115 r = slugify(txt)
116 self.assertEqual(r, "c-est-deja-l-ete")
117
118 txt = 'Nín hǎo. Wǒ shì zhōng guó rén'
119 r = slugify(txt)
120 self.assertEqual(r, "nin-hao-wo-shi-zhong-guo-ren")
121
122 txt = 'Компьютер'
123 r = slugify(txt)
124 self.assertEqual(r, "kompiuter")
125
126 txt = 'jaja---lol-méméméoo--a'
127 r = slugify(txt, max_length=9)
128 self.assertEqual(r, "jaja-lol")
129
130 txt = 'jaja---lol-méméméoo--a'
131 r = slugify(txt, max_length=15, word_boundary=True)
132 self.assertEqual(r, "jaja-lol-a")
133
134 txt = 'jaja---lol-méméméoo--a'
135 r = slugify(txt, max_length=20, word_boundary=True, separator=".")
136 self.assertEqual(r, "jaja.lol.mememeoo.a")
137
138 txt = 'one two three four five'
139 r = slugify(txt, max_length=13, word_boundary=True, save_order=True)
140 self.assertEqual(r, "one-two-three")
141
142 txt = 'the quick brown fox jumps over the lazy dog'
143 r = slugify(txt, stopwords=['the'])
144 self.assertEqual(r, 'quick-brown-fox-jumps-over-lazy-dog')
145
146 txt = 'the quick brown fox jumps over the lazy dog in a hurry'
147 r = slugify(txt, stopwords=['the', 'in', 'a', 'hurry'])
148 self.assertEqual(r, 'quick-brown-fox-jumps-over-lazy-dog')
149
150 txt = 'thIs Has a stopword Stopword'
151 r = slugify(txt, stopwords=['Stopword'], lowercase=False)
152 self.assertEqual(r, 'thIs-Has-a-stopword')
153
154 txt = "___This is a test___"
155 regex_pattern = r'[^-a-z0-9_]+'
156 r = slugify(txt, regex_pattern=regex_pattern)
157 self.assertEqual(r, "___this-is-a-test___")
158
159 txt = "___This is a test___"
160 regex_pattern = r'[^-a-z0-9_]+'
161 r = slugify(txt, separator='_', regex_pattern=regex_pattern)
162 self.assertNotEqual(r, "_this_is_a_test_")
163
164 txt = '10 | 20 %'
165 r = slugify(txt, replacements=[['|', 'or'], ['%', 'percent']])
166 self.assertEqual(r, "10-or-20-percent")
167
168 txt = 'ÜBER Über German Umlaut'
169 r = slugify(txt, replacements=[['Ü', 'UE'], ['ü', 'ue']])
170 self.assertEqual(r, "ueber-ueber-german-umlaut")
171
172 txt = 'i love 🦄'
173 r = slugify(txt, allow_unicode=True)
174 self.assertEqual(r, "i-love")
175
176 txt = 'i love 🦄'
177 r = slugify(txt, allow_unicode=True, regex_pattern=r'[^🦄]+')
178 self.assertEqual(r, "🦄")
179
180 ```
181
182 For more examples, have a look at the [test.py](test.py) file.
183
184 # Command Line Options
185
186 With the package, a command line tool called `slugify` is also installed.
187
188 It allows convenient command line access to all the features the `slugify` function supports. Call it with `-h` for help.
189
190 The command can take its input directly on the command line or from STDIN (when the `--stdin` flag is passed):
191
192 ```
193 $ echo "Taking input from STDIN" | slugify --stdin
194 taking-input-from-stdin
195 ```
196
197 ```
198 $ slugify taking input from the command line
199 taking-input-from-the-command-line
200 ```
201
202 Please note that when a multi-valued option such as `--stopwords` or `--replacements` is passed, you need to use `--` as separator before you start with the input:
203
204 ```
205 $ slugify --stopwords the in a hurry -- the quick brown fox jumps over the lazy dog in a hurry
206 quick-brown-fox-jumps-over-lazy-dog
207 ```
208
209 # Running the tests
210
211 To run the tests against the current environment:
212
213 python test.py
214
215 # Contribution
216
217 Please read the ([wiki](https://github.com/un33k/python-slugify/wiki/Python-Slugify-Wiki)) page prior to raising any PRs.
218
219 # License
220
221 Released under a ([MIT](LICENSE)) license.
222
223 ### Notes on GPL dependencies
224 Though the dependencies may be GPL licensed, `python-slugify` itself is not considered a derivative work and will remain under the MIT license.
225 If you wish to avoid installation of any GPL licensed packages, please note that the default dependency `text-unidecode` explicitly lets you choose to use the [Artistic License](https://opensource.org/license/artistic-perl-1-0-2/) instead. Use without concern.
226
227 # Version
228
229 X.Y.Z Version
230
231 `MAJOR` version -- when you make incompatible API changes,
232 `MINOR` version -- when you add functionality in a backwards-compatible manner, and
233 `PATCH` version -- when you make backwards-compatible bug fixes.
234
235 [status-image]: https://github.com/un33k/python-slugify/actions/workflows/ci.yml/badge.svg
236 [status-link]: https://github.com/un33k/python-slugify/actions/workflows/ci.yml
237 [version-image]: https://img.shields.io/pypi/v/python-slugify.svg
238 [version-link]: https://pypi.python.org/pypi/python-slugify
239 [coverage-image]: https://coveralls.io/repos/un33k/python-slugify/badge.svg
240 [coverage-link]: https://coveralls.io/r/un33k/python-slugify
241 [download-image]: https://img.shields.io/pypi/dm/python-slugify.svg
242 [download-link]: https://pypi.python.org/pypi/python-slugify
243
244 # Sponsors
245
246 [Neekware Inc.](http://neekware.com)