x-strings


Namex-strings JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/gergelyk/xstrings/
SummaryExtend Python syntax by defining custom string prefix
upload_time2024-11-06 19:02:53
maintainerNone
docs_urlNone
authorGrzegorz Krason
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # x-strings
![PyPI - Version](https://img.shields.io/pypi/v/x-strings)
![PyPI - License](https://img.shields.io/pypi/l/x-strings)
![PyPI - Downloads](https://img.shields.io/pypi/dm/x-strings)

Extend Python syntax by defining custom string prefix. Provide function that transforms strings with your prefix.

This corresponds to Tagged Template Literals feature in JavaScript.

This project is only a toy. Technique used here shouldn't be considered as a good coding practice due to the fact how it is implemented. I don't recommend using it in production code. Hopefully it can be inspiring though.

## Features

- Multiple encodings can be defined
- Multiple prefixes can be defined
- Prefixes can have more that one letter
- Encodings can take arguments (captured by regex)
- Doesn't corrupt Python syntax-error messages

## Examples

Simple example is shown below.

`app.py`:

```python
# coding: x-strings
print(x"Hello World")
```

`launcher.py`:

```python
import xstrings
xstrings.register({'x': lambda t: t + "!!!"})

import app
```

Notice exclamation marks added to the end of the message:
```sh
$ python3 -B examples/launcher.py
Hello World!!!
```

This and more advanced examples can be found in [here](https://github.com/gergelyk/xstrings/tree/master/examples).

## Caching

By default Python stores decoded code in `__pycache__`. Source file needs to be changed to get cache re-generated. This may complicate development of `launcher.py`. You can prevent Python from generating cache by either:

- Setting env var: `PYTHONDONTWRITEBYTECODE` to `1`
- Using `-B` switch for `python`
- Calling `sys.dont_write_bytecode = True` in the code

## References

Project is inspired by [pyxl4](https://github.com/pyxl4/pyxl4).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gergelyk/xstrings/",
    "name": "x-strings",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Grzegorz Krason",
    "author_email": "grzegorz.krason@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/79/ff/2812d0dc66e4378f9aa836c2231d967cb42ece241289cccded6aaf7b0691/x_strings-0.1.2.tar.gz",
    "platform": null,
    "description": "# x-strings\n![PyPI - Version](https://img.shields.io/pypi/v/x-strings)\n![PyPI - License](https://img.shields.io/pypi/l/x-strings)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/x-strings)\n\nExtend Python syntax by defining custom string prefix. Provide function that transforms strings with your prefix.\n\nThis corresponds to Tagged Template Literals feature in JavaScript.\n\nThis project is only a toy. Technique used here shouldn't be considered as a good coding practice due to the fact how it is implemented. I don't recommend using it in production code. Hopefully it can be inspiring though.\n\n## Features\n\n- Multiple encodings can be defined\n- Multiple prefixes can be defined\n- Prefixes can have more that one letter\n- Encodings can take arguments (captured by regex)\n- Doesn't corrupt Python syntax-error messages\n\n## Examples\n\nSimple example is shown below.\n\n`app.py`:\n\n```python\n# coding: x-strings\nprint(x\"Hello World\")\n```\n\n`launcher.py`:\n\n```python\nimport xstrings\nxstrings.register({'x': lambda t: t + \"!!!\"})\n\nimport app\n```\n\nNotice exclamation marks added to the end of the message:\n```sh\n$ python3 -B examples/launcher.py\nHello World!!!\n```\n\nThis and more advanced examples can be found in [here](https://github.com/gergelyk/xstrings/tree/master/examples).\n\n## Caching\n\nBy default Python stores decoded code in `__pycache__`. Source file needs to be changed to get cache re-generated. This may complicate development of `launcher.py`. You can prevent Python from generating cache by either:\n\n- Setting env var: `PYTHONDONTWRITEBYTECODE` to `1`\n- Using `-B` switch for `python`\n- Calling `sys.dont_write_bytecode = True` in the code\n\n## References\n\nProject is inspired by [pyxl4](https://github.com/pyxl4/pyxl4).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extend Python syntax by defining custom string prefix",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/gergelyk/xstrings/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fab6841a4993b0ce57350aa063b8bb092df8e930e041d437715ed73955cbc5fc",
                "md5": "98f29f5074fd3c65575b1d51a272d683",
                "sha256": "cedb86438563af60d267b003679f1f132edb1931b8dbcf5154a77497e826aad3"
            },
            "downloads": -1,
            "filename": "x_strings-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "98f29f5074fd3c65575b1d51a272d683",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 2587,
            "upload_time": "2024-11-06T19:02:52",
            "upload_time_iso_8601": "2024-11-06T19:02:52.534414Z",
            "url": "https://files.pythonhosted.org/packages/fa/b6/841a4993b0ce57350aa063b8bb092df8e930e041d437715ed73955cbc5fc/x_strings-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79ff2812d0dc66e4378f9aa836c2231d967cb42ece241289cccded6aaf7b0691",
                "md5": "db70bda1b3eb79d0373700142386c1c8",
                "sha256": "d835f5a6a8ba09a59aa86000350071232a0fb9d142b1ba1afd2cbf5f332ad7e7"
            },
            "downloads": -1,
            "filename": "x_strings-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "db70bda1b3eb79d0373700142386c1c8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 2334,
            "upload_time": "2024-11-06T19:02:53",
            "upload_time_iso_8601": "2024-11-06T19:02:53.941760Z",
            "url": "https://files.pythonhosted.org/packages/79/ff/2812d0dc66e4378f9aa836c2231d967cb42ece241289cccded6aaf7b0691/x_strings-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-06 19:02:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gergelyk",
    "github_project": "xstrings",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "x-strings"
}
        
Elapsed time: 0.69809s