Skip to main content

Get identifiers, names, paths, URLs and words from the command output.
The xontrib-output-search for xonsh shell is using this library.

If you like the idea click ⭐ on the repo and stay tuned by watching releases.

Install

pip install -U tokenize-output

Usage

You can use tokenize-output command as well as export the tokenizers in Python:

from tokenize_output.tokenize_output import *
tokenizer_split("Hello world!")
# {'final': set(), 'new': {'Hello', 'world!'}}

Words tokenizing

echo "Try https://github.com/xxh/xxh" | tokenize-output -p
# Try
# https://github.com/xxh/xxh

JSON, Python dict and JavaScript object tokenizing

echo '{"Try": "xonsh shell"}' | tokenize-output -p
# Try
# shell
# xonsh
# xonsh shell

env tokenizing

echo 'PATH=/one/two:/three/four' | tokenize-output -p
# /one/two
# /one/two:/three/four
# /three/four
# PATH

Development

Tokenizers

Tokenizer is a functions which extract tokens from the text.

Priority Tokenizer Text example Tokens
1 dict {"key": "val as str"} key, val as str
2 env PATH=/bin:/etc PATH, /bin:/etc, /bin, /etc
3 split Split me \n now! Split, me, now!
4 strip {Hello}!. Hello

You can create your tokenizer and add it to tokenizers_all in tokenize_output.py.

Tokenizing is a recursive process where every tokenizer returns final and new tokens. The final tokens directly go to the result list of tokens. The new tokens go to all tokenizers again to find new tokens. As result if there is a mix of json and env data in the output it will be found and tokenized in appropriate way.

How to add tokenizer

You can start from env tokenizer:

  1. Prepare regexp
  2. Prepare tokenizer function
  3. Add the function to the list and to the preset.
  4. Add test.
  5. Now you can test and debug (see below).

Test and debug

Run tests:

cd ~
git clone https://github.com/anki-code/tokenize-output
cd tokenize-output
python -m pytest tests/

To debug the tokenizer:

echo "Hello world" | ./tokenize-output -p

Related projects

Metadata

Release files for tokenize-output 0.4.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokenize-output 0.4.10
File Size Uploaded Provenance Actions
tokenize-output-0.4.10.tar.gz 5.5 kB Without provenance Details for tokenize-output-0.4.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokenize-output 0.4.10
File Interpreter ABI Platform Actions
tokenize_output-0.4.10-py3-none-any.whl Python 3 none any Details for tokenize_output-0.4.10-py3-none-any.whl

Total release size: 11.5 kB

Release files / tokenize-output-0.4.10.tar.gz

Download URL tokenize-output-0.4.10.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2930974b5e47e3fb12be4526085b87a2fcc96781c995c30645c33ea9c8d4d011
BLAKE2b-256 checksum
How to use checksums
4b18a301ad7a8ad40744179544a377c9e660ad6de18321159986aa4f93a859ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / tokenize_output-0.4.10-py3-none-any.whl

Download URL tokenize_output-0.4.10-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1efb30e229d26840e5ff4c23c9d8fcfb059a641c20b3286fdf29ebaaab9bdb5c
BLAKE2b-256 checksum
How to use checksums
0eac616053a95c2ab3eddf086222235434287124887369d700eb089eb5f337da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for tokenize-output 0.4.10

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page