token-utils
Installation: pip install token-utils.
The purpose of token-utils is to simplify manipulations of tokens normally obtaind from Python's tokenize module.
To get an idea of the simplicity of using token-utils, consider this example from Python's own documentation which substitute Decimals for floats in a string of statements:
from tokenize import tokenize, untokenize, NUMBER, STRING, NAME, OP
from io import BytesIO
def decistmt(s):
result = []
g = tokenize(BytesIO(s.encode('utf-8')).readline) # tokenize the string
for toknum, tokval, _, _, _ in g:
if toknum == NUMBER and '.' in tokval: # replace NUMBER tokens
result.extend([
(NAME, 'Decimal'),
(OP, '('),
(STRING, repr(tokval)),
(OP, ')')
])
else:
result.append((toknum, tokval))
return untokenize(result).decode('utf-8')
Here's how you could achieve the same result with token-utils:
from token_utils import tokenize, untokenize
def decistmt(source):
tokens = tokenize(source)
for token in tokens:
if token.is_float():
token.string = f"Decimal('{token.string}')"
return untokenize(tokens)
See the documentation for more information.
Metadata
Release files for token-utils 0.3.11
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 | Actions |
|---|---|---|---|---|
| token_utils-0.3.11.tar.gz | 4.0 MB | Without provenance | Details for token_utils-0.3.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| token_utils-0.3.11-py3-none-any.whl | Python 3 | none | any | Details for token_utils-0.3.11-py3-none-any.whl |
Total release size: 4.0 MB
Release files / token_utils-0.3.11.tar.gz
| Download URL | token_utils-0.3.11.tar.gz |
|---|---|
| Size | 4.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc35743db1333a2dc3121ebe5089a442485a7257e5ce693be814db36d371f78c
|
|
BLAKE2b-256 checksum How to use checksums |
210d7d7c4b4389039729b16a4d765c3a7dfbc7f8d19653f0fab23f63da9ec0c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / token_utils-0.3.11-py3-none-any.whl
| Download URL | token_utils-0.3.11-py3-none-any.whl |
|---|---|
| Size | 26.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e12fb6de13a40f5b9d993349dfa515f33b7a33afec85b5fc9fabced920cc547b
|
|
BLAKE2b-256 checksum How to use checksums |
09a45af8a28cec7d5c7524ff100435bf2f031e69f7c8bed810fbb397d0318cc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for token-utils 0.3.11
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.