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:
# coding: x-strings
print(x"Hello World")
launcher.py:
import xstrings
xstrings.register({'x': lambda t: t + "!!!"})
import app
Notice exclamation marks added to the end of the message:
$ python3 -B examples/launcher.py
Hello World!!!
This and more advanced examples can be found in here.
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:
PYTHONDONTWRITEBYTECODEto1 - Using
-Bswitch forpython - Calling
sys.dont_write_bytecode = Truein the code
References
Project is inspired by pyxl4.
Metadata
Release files for x-strings 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| x_strings-0.1.2.tar.gz | 2.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| x_strings-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.9 kB
Release files / x_strings-0.1.2.tar.gz
| Download URL | x_strings-0.1.2.tar.gz |
|---|---|
| Size | 2.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d835f5a6a8ba09a59aa86000350071232a0fb9d142b1ba1afd2cbf5f332ad7e7
|
|
BLAKE2b-256 checksum How to use checksums |
79ff2812d0dc66e4378f9aa836c2231d967cb42ece241289cccded6aaf7b0691
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.10.6 Linux/5.15.0-56-generic
|
Release files / x_strings-0.1.2-py3-none-any.whl
| Download URL | x_strings-0.1.2-py3-none-any.whl |
|---|---|
| Size | 2.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cedb86438563af60d267b003679f1f132edb1931b8dbcf5154a77497e826aad3
|
|
BLAKE2b-256 checksum How to use checksums |
fab6841a4993b0ce57350aa063b8bb092df8e930e041d437715ed73955cbc5fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.10.6 Linux/5.15.0-56-generic
|
Security for x-strings 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.