{"id":13416161,"url":"https://github.com/un33k/python-slugify","last_synced_at":"2025-05-13T21:08:19.496Z","repository":{"id":5058746,"uuid":"6220331","full_name":"un33k/python-slugify","owner":"un33k","description":"Returns unicode slugs","archived":false,"fork":false,"pushed_at":"2024-03-01T18:21:18.000Z","size":200,"stargazers_count":1526,"open_issues_count":3,"forks_count":108,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-28T12:15:21.145Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"DBCDK/dbc-react-components","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/un33k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-15T01:44:50.000Z","updated_at":"2025-04-13T16:05:49.000Z","dependencies_parsed_at":"2023-07-05T20:17:13.022Z","dependency_job_id":"0cc6c837-9dcc-4108-b22c-487f11dda479","html_url":"https://github.com/un33k/python-slugify","commit_stats":null,"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un33k%2Fpython-slugify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un33k%2Fpython-slugify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un33k%2Fpython-slugify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un33k%2Fpython-slugify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/un33k","download_url":"https://codeload.github.com/un33k/python-slugify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251311334,"owners_count":21569009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:54.871Z","updated_at":"2025-04-28T12:15:25.694Z","avatar_url":"https://github.com/un33k.png","language":"Python","readme":"# Python Slugify\n\n**A Python slugify application that handles unicode**.\n\n[![status-image]][status-link]\n[![version-image]][version-link]\n[![coverage-image]][coverage-link]\n\n# Overview\n\n**Best attempt** to create slugs from unicode strings while keeping it **DRY**.\n\n# Notice\n\nThis module, by default installs and uses [text-unidecode](https://github.com/kmike/text-unidecode) _(GPL \u0026 Perl Artistic)_ for its decoding needs.\n\nHowever, 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).\n\n### `Official` Support Matrix\n\n| Python         | Slugify            |\n| -------------- | ------------------ |\n| `\u003e= 2.7 \u003c 3.6` | `\u003c 5.0.0`          |\n| `\u003e= 3.6 \u003c 3.7` | `\u003e= 5.0.0 \u003c 7.0.0` |\n| `\u003e= 3.7`       | `\u003e= 7.0.0`         |\n\n# How to install\n\n    easy_install python-slugify |OR| easy_install python-slugify[unidecode]\n    -- OR --\n    pip install python-slugify |OR| pip install python-slugify[unidecode]\n\n# Options\n\n```python\ndef slugify(\n    text: str,\n    entities: bool = True,\n    decimal: bool = True,\n    hexadecimal: bool = True,\n    max_length: int = 0,\n    word_boundary: bool = False,\n    separator: str = DEFAULT_SEPARATOR,\n    save_order: bool = False,\n    stopwords: Iterable[str] = (),\n    regex_pattern: str | None = None,\n    lowercase: bool = True,\n    replacements: Iterable[Iterable[str]] = (),\n    allow_unicode: bool = False,\n) -\u003e str:\n  \"\"\"\n  Make a slug from the given text.\n  :param text (str): initial text\n  :param entities (bool): converts html entities to unicode (foo \u0026amp; bar -\u003e foo-bar)\n  :param decimal (bool): converts html decimal to unicode (\u0026#381; -\u003e Ž -\u003e z)\n  :param hexadecimal (bool): converts html hexadecimal to unicode (\u0026#x17D; -\u003e Ž -\u003e z)\n  :param max_length (int): output string length\n  :param word_boundary (bool): truncates to end of full words (length may be shorter than max_length)\n  :param save_order (bool): if parameter is True and max_length \u003e 0 return whole words in the initial order\n  :param separator (str): separator between words\n  :param stopwords (iterable): words to discount\n  :param regex_pattern (str): regex pattern for disallowed characters\n  :param lowercase (bool): activate case sensitivity by setting it to False\n  :param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]\n  :param allow_unicode (bool): allow unicode characters\n  :return (str): slugify text\n  \"\"\"\n```\n\n# How to use\n\n```python\nfrom slugify import slugify\n\ntxt = \"This is a test ---\"\nr = slugify(txt)\nself.assertEqual(r, \"this-is-a-test\")\n\ntxt = '影師嗎'\nr = slugify(txt)\nself.assertEqual(r, \"ying-shi-ma\")\n\ntxt = '影師嗎'\nr = slugify(txt, allow_unicode=True)\nself.assertEqual(r, \"影師嗎\")\n\ntxt = 'C\\'est déjà l\\'été.'\nr = slugify(txt)\nself.assertEqual(r, \"c-est-deja-l-ete\")\n\ntxt = 'Nín hǎo. Wǒ shì zhōng guó rén'\nr = slugify(txt)\nself.assertEqual(r, \"nin-hao-wo-shi-zhong-guo-ren\")\n\ntxt = 'Компьютер'\nr = slugify(txt)\nself.assertEqual(r, \"kompiuter\")\n\ntxt = 'jaja---lol-méméméoo--a'\nr = slugify(txt, max_length=9)\nself.assertEqual(r, \"jaja-lol\")\n\ntxt = 'jaja---lol-méméméoo--a'\nr = slugify(txt, max_length=15, word_boundary=True)\nself.assertEqual(r, \"jaja-lol-a\")\n\ntxt = 'jaja---lol-méméméoo--a'\nr = slugify(txt, max_length=20, word_boundary=True, separator=\".\")\nself.assertEqual(r, \"jaja.lol.mememeoo.a\")\n\ntxt = 'one two three four five'\nr = slugify(txt, max_length=13, word_boundary=True, save_order=True)\nself.assertEqual(r, \"one-two-three\")\n\ntxt = 'the quick brown fox jumps over the lazy dog'\nr = slugify(txt, stopwords=['the'])\nself.assertEqual(r, 'quick-brown-fox-jumps-over-lazy-dog')\n\ntxt = 'the quick brown fox jumps over the lazy dog in a hurry'\nr = slugify(txt, stopwords=['the', 'in', 'a', 'hurry'])\nself.assertEqual(r, 'quick-brown-fox-jumps-over-lazy-dog')\n\ntxt = 'thIs Has a stopword Stopword'\nr = slugify(txt, stopwords=['Stopword'], lowercase=False)\nself.assertEqual(r, 'thIs-Has-a-stopword')\n\ntxt = \"___This is a test___\"\nregex_pattern = r'[^-a-z0-9_]+'\nr = slugify(txt, regex_pattern=regex_pattern)\nself.assertEqual(r, \"___this-is-a-test___\")\n\ntxt = \"___This is a test___\"\nregex_pattern = r'[^-a-z0-9_]+'\nr = slugify(txt, separator='_', regex_pattern=regex_pattern)\nself.assertNotEqual(r, \"_this_is_a_test_\")\n\ntxt = '10 | 20 %'\nr = slugify(txt, replacements=[['|', 'or'], ['%', 'percent']])\nself.assertEqual(r, \"10-or-20-percent\")\n\ntxt = 'ÜBER Über German Umlaut'\nr = slugify(txt, replacements=[['Ü', 'UE'], ['ü', 'ue']])\nself.assertEqual(r, \"ueber-ueber-german-umlaut\")\n\ntxt = 'i love 🦄'\nr = slugify(txt, allow_unicode=True)\nself.assertEqual(r, \"i-love\")\n\ntxt = 'i love 🦄'\nr = slugify(txt, allow_unicode=True, regex_pattern=r'[^🦄]+')\nself.assertEqual(r, \"🦄\")\n\n```\n\nFor more examples, have a look at the [test.py](test.py) file.\n\n# Command Line Options\n\nWith the package, a command line tool called `slugify` is also installed.\n\nIt allows convenient command line access to all the features the `slugify` function supports. Call it with `-h` for help.\n\nThe command can take its input directly on the command line or from STDIN (when the `--stdin` flag is passed):\n\n```\n$ echo \"Taking input from STDIN\" | slugify --stdin\ntaking-input-from-stdin\n```\n\n```\n$ slugify taking input from the command line\ntaking-input-from-the-command-line\n```\n\nPlease 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:\n\n```\n$ slugify --stopwords the in a hurry -- the quick brown fox jumps over the lazy dog in a hurry\nquick-brown-fox-jumps-over-lazy-dog\n```\n\n# Running the tests\n\nTo run the tests against the current environment:\n\n    python test.py\n\n# Contribution\n\nPlease read the ([wiki](https://github.com/un33k/python-slugify/wiki/Python-Slugify-Wiki)) page prior to raising any PRs.\n\n# License\n\nReleased under a ([MIT](LICENSE)) license.\n\n### Notes on GPL dependencies\nThough the dependencies may be GPL licensed, `python-slugify` itself is not considered a derivative work and will remain under the MIT license.  \nIf 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.\n\n# Version\n\nX.Y.Z Version\n\n    `MAJOR` version -- when you make incompatible API changes,\n    `MINOR` version -- when you add functionality in a backwards-compatible manner, and\n    `PATCH` version -- when you make backwards-compatible bug fixes.\n\n[status-image]: https://github.com/un33k/python-slugify/actions/workflows/ci.yml/badge.svg\n[status-link]: https://github.com/un33k/python-slugify/actions/workflows/ci.yml\n[version-image]: https://img.shields.io/pypi/v/python-slugify.svg\n[version-link]: https://pypi.python.org/pypi/python-slugify\n[coverage-image]: https://coveralls.io/repos/un33k/python-slugify/badge.svg\n[coverage-link]: https://coveralls.io/r/un33k/python-slugify\n[download-image]: https://img.shields.io/pypi/dm/python-slugify.svg\n[download-link]: https://pypi.python.org/pypi/python-slugify\n\n# Sponsors\n\n[Neekware Inc.](http://neekware.com)\n","funding_links":[],"categories":["Python Packages","Python","Text Processing","资源列表","Data Format \u0026 I/O","文本处理","Text Data","Text Processing [🔝](#readme)","Awesome Python"],"sub_categories":["Views","文本处理","For Python","URLs","Templates","Text Processing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fun33k%2Fpython-slugify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fun33k%2Fpython-slugify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fun33k%2Fpython-slugify/lists"}