string-kit


Namestring-kit JSON
Version 0.1.0a4 PyPI version JSON
download
home_pageNone
SummaryLibrary of string functions and formatters
upload_time2025-03-03 04:34:56
maintainerNone
docs_urlNone
authorNone
requires_python>=3.13
licenseMIT License Copyright (c) 2025 Aalap Shah Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords string formatter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. |package-name| replace:: string-kit

.. |pypi-version| image:: https://img.shields.io/pypi/v/string-kit?label=PyPI%20Version&color=4BC51D
   :alt: PyPI Version
   :target: https://pypi.org/projects/string-kit/

.. |pypi-downloads| image:: https://img.shields.io/pypi/dm/string-kit?label=PyPI%20Downloads&color=037585
   :alt: PyPI Downloads
   :target: https://pypi.org/projects/string-kit/

string-kit
##########

|pypi-version| |pypi-downloads|

Description
***********

Provides advanced string utilities and a powerful Formatter.

This is a development version, and while it has been thoroughly tested, it will be battle-tested in a live project and updated as needed.

PowerFormatter
==============

``PowerFormatter`` is a drop-in replacement of ``str.Formatter`` and supports the same syntax and more.

``PowerFormatter`` adds the following features:
 - virtual fields ``now``, ``uuid1``, ``uuid4``, ``uuid5`` (no key is required in the format parameters, however if present, they take precedence); many more coming up.
 - user-defined virtual fields can be added through ``field_default`` init parm.
 - can send namespaces where format field values are searched through ``namespaces`` init parm.
 - ``!capitalize``, ``!lower``, ``!lstrip``, ``!rstrip``, ``!slug``, ``!strip``, ``!title``, ``upper``; many more coming up.
 - user-defined convertors can be added through ``convertors`` init parm.
 - chained conversions and format specifications in any order: ``{field!slug:.10s!upper}``.
 - user-configurable ``silence_missing_fields``, if set ``True``, will suppress ``IndexError`` and ``KeyError`` and will quietly replace with empty string.
 - user-configurable characters to identify fields (default ``{}``), convertors (default ``!``) and format specifiers (default ``:``).

A simple example:

.. code-block:: python

   import random
   from string_kit import PowerFormatter

   my_field_defaults = {
       "greeting": "Hello",
       "password": lambda: random.choice(["lI0n", "rAbb1t", "tig3R"]) \
                           + str(random.randint(100, 999)),
   }

   my_weather = "Sunny and Wet"

   my_convertors = {
       "s2d": lambda s: s.replace(" ", "-")
   }

   pf = PowerFormatter(
       silence_missing_fields=True,
       field_defaults=my_field_defaults,  # optional, dict with str or callable values
       convertors=my_convertors,          # optional, dict with callable values
       field_namespaces=[locals()],       # optional, namespaces to search for field names
   )

   print(pf.format("{greeting!upper} {fname!s2d}, this is your random password:"
                   " '{password}'.", fname="Charlie Brown"))
   # "HELLO Charlie-Brown, this is your random password: 'rAbb1t530'."

   print(pf.format("Today is a {my_weather:.5!lower} day.{inexistent!lstrip}"))
   # "Today is a sunny day."

Some TODO Ideas
===============

 - somehow send static parameters to convertors in format string, e.g. replace convertor with field-level replace string, i.e. ``{field:!replace(x,y)}```
 - add ``snake_case``, ``kebab-case``, ``PascalCase``, ``camelCase`` as built-in convertors
 - add ``sqids`` convertor with parameters (strings allowed, length) passed as static values

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "string-kit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.13",
    "maintainer_email": null,
    "keywords": "string formatter",
    "author": null,
    "author_email": "\"Aalap Shah (aka fishfin)\" <shah.aalap@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/67/68/ce28e45b63b3f7f05f61fb49522302bb760e3d2c5f19d984982f556e506a/string_kit-0.1.0a4.tar.gz",
    "platform": null,
    "description": ".. |package-name| replace:: string-kit\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/string-kit?label=PyPI%20Version&color=4BC51D\n   :alt: PyPI Version\n   :target: https://pypi.org/projects/string-kit/\n\n.. |pypi-downloads| image:: https://img.shields.io/pypi/dm/string-kit?label=PyPI%20Downloads&color=037585\n   :alt: PyPI Downloads\n   :target: https://pypi.org/projects/string-kit/\n\nstring-kit\n##########\n\n|pypi-version| |pypi-downloads|\n\nDescription\n***********\n\nProvides advanced string utilities and a powerful Formatter.\n\nThis is a development version, and while it has been thoroughly tested, it will be battle-tested in a live project and updated as needed.\n\nPowerFormatter\n==============\n\n``PowerFormatter`` is a drop-in replacement of ``str.Formatter`` and supports the same syntax and more.\n\n``PowerFormatter`` adds the following features:\n - virtual fields ``now``, ``uuid1``, ``uuid4``, ``uuid5`` (no key is required in the format parameters, however if present, they take precedence); many more coming up.\n - user-defined virtual fields can be added through ``field_default`` init parm.\n - can send namespaces where format field values are searched through ``namespaces`` init parm.\n - ``!capitalize``, ``!lower``, ``!lstrip``, ``!rstrip``, ``!slug``, ``!strip``, ``!title``, ``upper``; many more coming up.\n - user-defined convertors can be added through ``convertors`` init parm.\n - chained conversions and format specifications in any order: ``{field!slug:.10s!upper}``.\n - user-configurable ``silence_missing_fields``, if set ``True``, will suppress ``IndexError`` and ``KeyError`` and will quietly replace with empty string.\n - user-configurable characters to identify fields (default ``{}``), convertors (default ``!``) and format specifiers (default ``:``).\n\nA simple example:\n\n.. code-block:: python\n\n   import random\n   from string_kit import PowerFormatter\n\n   my_field_defaults = {\n       \"greeting\": \"Hello\",\n       \"password\": lambda: random.choice([\"lI0n\", \"rAbb1t\", \"tig3R\"]) \\\n                           + str(random.randint(100, 999)),\n   }\n\n   my_weather = \"Sunny and Wet\"\n\n   my_convertors = {\n       \"s2d\": lambda s: s.replace(\" \", \"-\")\n   }\n\n   pf = PowerFormatter(\n       silence_missing_fields=True,\n       field_defaults=my_field_defaults,  # optional, dict with str or callable values\n       convertors=my_convertors,          # optional, dict with callable values\n       field_namespaces=[locals()],       # optional, namespaces to search for field names\n   )\n\n   print(pf.format(\"{greeting!upper} {fname!s2d}, this is your random password:\"\n                   \" '{password}'.\", fname=\"Charlie Brown\"))\n   # \"HELLO Charlie-Brown, this is your random password: 'rAbb1t530'.\"\n\n   print(pf.format(\"Today is a {my_weather:.5!lower} day.{inexistent!lstrip}\"))\n   # \"Today is a sunny day.\"\n\nSome TODO Ideas\n===============\n\n - somehow send static parameters to convertors in format string, e.g. replace convertor with field-level replace string, i.e. ``{field:!replace(x,y)}```\n - add ``snake_case``, ``kebab-case``, ``PascalCase``, ``camelCase`` as built-in convertors\n - add ``sqids`` convertor with parameters (strings allowed, length) passed as static values\n",
    "bugtrack_url": null,
    "license": "MIT License                  Copyright (c) 2025 Aalap Shah                  Permission is hereby granted, free of charge, to any person obtaining a copy         of this software and associated documentation files (the \"Software\"), to deal         in the Software without restriction, including without limitation the rights         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell         copies of the Software, and to permit persons to whom the Software is         furnished to do so, subject to the following conditions:                  The above copyright notice and this permission notice shall be included in all         copies or substantial portions of the Software.                  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE         SOFTWARE.",
    "summary": "Library of string functions and formatters",
    "version": "0.1.0a4",
    "project_urls": {
        "Homepage": "https://gitlab.com/shah-aalap/python-string-kit"
    },
    "split_keywords": [
        "string",
        "formatter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "077c139e1687eca350a21b0153ddad994b0ac9e8af5f48673a9477ac801fec5c",
                "md5": "a10dcc2008554f5dc0488f550be710cb",
                "sha256": "bf9f68ab02a17199724647c0a1f348c6554b7ca05fed1a221a31be13e5c76a84"
            },
            "downloads": -1,
            "filename": "string_kit-0.1.0a4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a10dcc2008554f5dc0488f550be710cb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.13",
            "size": 10269,
            "upload_time": "2025-03-03T04:34:54",
            "upload_time_iso_8601": "2025-03-03T04:34:54.961007Z",
            "url": "https://files.pythonhosted.org/packages/07/7c/139e1687eca350a21b0153ddad994b0ac9e8af5f48673a9477ac801fec5c/string_kit-0.1.0a4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6768ce28e45b63b3f7f05f61fb49522302bb760e3d2c5f19d984982f556e506a",
                "md5": "e5c06d534bd66ad0d8895c7554b12287",
                "sha256": "30baa5ee9dd7de1083193599cdd0d5fd7179c0bfc176203b419a8fe4692bb5b4"
            },
            "downloads": -1,
            "filename": "string_kit-0.1.0a4.tar.gz",
            "has_sig": false,
            "md5_digest": "e5c06d534bd66ad0d8895c7554b12287",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.13",
            "size": 10071,
            "upload_time": "2025-03-03T04:34:56",
            "upload_time_iso_8601": "2025-03-03T04:34:56.792462Z",
            "url": "https://files.pythonhosted.org/packages/67/68/ce28e45b63b3f7f05f61fb49522302bb760e3d2c5f19d984982f556e506a/string_kit-0.1.0a4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-03 04:34:56",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "shah-aalap",
    "gitlab_project": "python-string-kit",
    "lcname": "string-kit"
}
        
Elapsed time: 0.42710s