Skip to main content

Installation

pip install fastpylight

fastpylight is a small Python/Rust wrapper around Lumis, a Tree-sitter syntax highlighter with Neovim themes. Language names, token scopes, and theme names follow Lumis.

Python

from fastpylight import highlight, highlight_spans, guess, theme_css

code = "def f(x):\n    return x + 1\n"

# Output for the CSS Highlight API.
html = highlight(code, "python")

# Static span output.
spans = highlight_spans(code, "python", "hl-")

# CSS rules for the span output.
css = theme_css("github_light", "pre code", "hl-")

highlight returns HTML with token ranges in UTF-16 code units, for use with the CSS Highlight API:

<hl-code toks='[[0,3,"keyword"],[4,5,"function"],[6,7,"variable"],[14,20,"keyword"],[21,22,"variable"],[23,24,"operator"],[25,26,"number"]]'><pre><code>def f(x):
    return x + 1
</code></pre></hl-code>

highlight_spans returns normal HTML spans:

<pre><code><span class="hl-keyword">def</span> <span class="hl-function">f</span>(<span class="hl-variable">x</span>):
    <span class="hl-keyword">return</span> <span class="hl-variable">x</span> <span class="hl-operator">+</span> <span class="hl-number">1</span>
</code></pre>

The exact classes depend on Lumis scopes. A complete GitHub Light CSS example for both output modes is in docs/github_light.css.

Languages

The default language set enables Lumis web, web-extra, system, and backend bundles, plus R, Julia, PowerShell, Lua, Swift, MATLAB, Perl, Pascal, Fortran, and Objective-C.

Markdown is treated as quotation: fenced code bodies and other injected languages flatten to the markup.raw.block scope instead of being highlighted as the embedded language, so markdown source specimens read as markdown. Markdown's own structure (headings, fence markers, info strings, inline code) keeps its scopes.

languages() lists every available name. The highlighting functions need an exact language name and raise ValueError on an unknown one. Use "plaintext" for un-highlighted output:

highlight(code, "plaintext")  # toks='[]', no tokens

To detect a language instead of specifying one, use guess, which takes the code plus an optional hint (a name, extension, or filename) and falls back to "plaintext" when nothing matches:

guess("fn main() {}", "rs")        # 'rust'  (extension hint)
guess("#!/usr/bin/env python\n")   # 'python' (shebang)
guess("just some prose")           # 'plaintext' (no match)

highlight(code, guess(code))       # detect, then highlight

CSS Highlight API

The highlight function is for browser code that applies token ranges with the CSS Highlight API. component_js() returns the reference component:

class HlCode extends HTMLElement {
  connectedCallback(){
    if(!CSS.highlights) return;
    setTimeout(() => {
      const d=this.getAttribute('toks'); if(!d) return;
      const tn=this.querySelector('code').firstChild, toks=JSON.parse(d);
      this._ranges=[];
      toks.forEach(([s,e,k])=>{
        const r=new Range(); r.setStart(tn,s); r.setEnd(tn,e);
        const h=CSS.highlights.get(k)||new Highlight();
        h.add(r); CSS.highlights.set(k,h);
        this._ranges.push([r,k]);
      });
      this.removeAttribute('toks');
    }, 0);
  }
  disconnectedCallback(){
    if(!this._ranges) return;
    this._ranges.forEach(([r,k])=>{
      const h=CSS.highlights.get(k); if(h) h.delete(r);
    });
    this._ranges=null;
  }
}
if(!customElements.get('hl-code')) customElements.define('hl-code',HlCode);

highlight needs ::highlight(...) rules. highlight_spans needs class rules. docs/github_light.css includes both for the default hl- prefix.

You can generate CSS at runtime:

highlight_css = theme_css("github_light")
span_css = theme_css("github_light", "pre code", "hl-")

For non-CSS consumers (e.g. document converters), theme_colors("github_light") returns the same theme as data: a dict of dotted scope names (including normal, which the CSS omits) to {'fg', 'bg', 'bold', 'italic', 'underline', 'strikethrough'}.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastpylight-0.1.14.tar.gz (23.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastpylight-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fastpylight-0.1.14-cp313-cp313-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fastpylight-0.1.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastpylight-0.1.14-cp312-cp312-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastpylight-0.1.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastpylight-0.1.14-cp311-cp311-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastpylight-0.1.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastpylight-0.1.14-cp310-cp310-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file fastpylight-0.1.14.tar.gz.

File metadata

  • Download URL: fastpylight-0.1.14.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14.tar.gz
Algorithm Hash digest
SHA256 71cb527d829556ee6a5b18aca05cbd09c227a87d33fece29e12607817ca413af
MD5 9142913f36b5a93566125c733addcf41
BLAKE2b-256 b9a9601ca3c6aa8328e09d948dec396a88170d72dc57560509d3959f9e548342

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 795a26a452051bd25236d0cef24571e41bab70098544ff21c8661fed70a24ae8
MD5 9840d3a502c143e1285bde4bbd625fd2
BLAKE2b-256 d67a046e14eafc52ef20df975beb9a8d99d12e80fc1450d7a566fd311b156cd0

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66f9bd6404e3c55580dbd5259eea4dce512dada29a5942c4dba65bf04187001e
MD5 d7bc5e0dfccb6bc2ec03efcbc365f9bf
BLAKE2b-256 200d3d4d9ba3284c81fa5161b0a0a66f8bc2d9ceceed253e4a2a230ec63ac4d3

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4b1a216976d12698497389040f32d276036aad8aebee3ea09f246b081031761
MD5 016ae47d53bc5586255b707920cda2e2
BLAKE2b-256 b30c832414c44c35a7d5a1f3bbaeffb38fbf44da3bc889d40f9a7a94ecce7c5f

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c689ac542962ece126b2e9e62061c839d772ce62c4c2d0f86c8f4029bc535517
MD5 a25fdf6f16d158405637880641fcfd65
BLAKE2b-256 d9eff96835883177da2d7d023fd7c252175f4c0819efe2bb6267ced41e8a00e6

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e0ca4bc0995b153ad8b9c2c7886bdfa4cdd693985edf14cdc2ffaeef4382136
MD5 9d3da65454ceb1d5ce758072f3d995e8
BLAKE2b-256 903c18ae6f7100a786d6feae009aee836c795fb8a97edecac317d5a9ed8f827c

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp311-cp311-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.11, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 74d36af55d3521e42e0d4d022c3ba28e2a2431c5a8b8331df5f5f961d77fb0c2
MD5 58215c8afc48cbf8453896a5dea652c5
BLAKE2b-256 8b21cfeadc5f0bac0a45c63c7c9abca7e5462dff0de84df1d9fee4cf5e6654db

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 211492a5b78b05101edcd2c0a409f9575084ba11281db181602c6367ab886dc0
MD5 3ed69aa1cd9bc1d196167eb80b99f4c0
BLAKE2b-256 d0939c2712d53b14ea0e837e4deb319ff0a119a94a1e7feefbacc79a40c5e918

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.14-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.14-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastpylight-0.1.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ff86309910444aa4d4676b47873e3e96d32023414f265c046fbd49b070a9195
MD5 381c18f14ecdcf35c26bba99a3e2d4fe
BLAKE2b-256 597a50b5ec2e62a4d87114feb04f22ffe560fe64e45ddd7fe124660fc1b7a18d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page