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.16.tar.gz (24.8 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.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fastpylight-0.1.16-cp313-cp313-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fastpylight-0.1.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastpylight-0.1.16-cp312-cp312-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastpylight-0.1.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastpylight-0.1.16-cp311-cp311-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastpylight-0.1.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastpylight-0.1.16-cp310-cp310-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: fastpylight-0.1.16.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16.tar.gz
Algorithm Hash digest
SHA256 c9a4bd7051ef03e047b0c98750c090ebac46bd146493d41d2828dbef9a9da032
MD5 1d2f7a0985aadf032b6e35011f568fb0
BLAKE2b-256 cb26b8434424820b3bf0b1c3b250d5d52ef3252dd86a11f292de5034b2b64a0b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8d73abdca32951ab60f45ef38aaa6d3d21f67ad37426e97eee4ecaeed8f48f5f
MD5 ff874d8c17131752ae1f6f155b6f075b
BLAKE2b-256 c0e157a5a7db9a05eb04aed8193ba6257afbe02473d33eed8440be5a75627727

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bcbbe54eb14952b347a8c0fab1fa694d60be07d5cc381f04c7dbef465e2435e
MD5 385a42aa075797669440cb1f6d43fc9e
BLAKE2b-256 2d6771e309b91a193a431cc5344a542b0e1108b51570f64dd91434a9f68e971a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f92602ba3767fd9ef158a939a896990b37c68d2ac77c6debfb65140188dd65c
MD5 aa65245c91ea4e80bbdd5db71e56f053
BLAKE2b-256 2cccbb3d65498c937472a7046dae2b4c918d757e0fc941d44cbc6a11417261cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c951d7ec7360afd39873bca6127810b718ebf9d935579ba8b37a73cb68f9a98
MD5 f7536de682722b1279b1966878d9b461
BLAKE2b-256 9cc9868e076f6722743b7e2d13a4239181afccf3018b890bafef37760f6ac2f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e00cce1a1e3839cb0a5885b1c401439bc81eb0b9409b40d3cecf2f5e1add061b
MD5 65372484f29d75ca83724f352c5a53b8
BLAKE2b-256 2256e690419d2baecfbbc692ace48e99f6bf54f3e730f9f5ca6e0c2bc6ebb834

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp311-cp311-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: CPython 3.11, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0701ce3e00cfbf793c7377aa4281be7c711781b2398c2d507d0ea2cf72ab858b
MD5 dc69b795b764f14f42eb38e5038581b3
BLAKE2b-256 3c3f74cdfe0bba7ed4389564f80e153580174518ec57c99db61c12c2091ede2a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d14178430f590a7f07838d0b5fe5820c1ea81fa1d646c5a0352e05b81ce74c6
MD5 d0f93f99814c9a9eacd9811e05a3734f
BLAKE2b-256 f718ddd9920016e888cb8118f5550e39e820645b3b7bcf3effa06cfadf1ab537

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastpylight-0.1.16-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.16-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4223d3b7e1559b536365a1cfe0b6d776d1b03d117fac6c7bac08edf65af4e16c
MD5 293f86cdaadda0305378057f21eff40c
BLAKE2b-256 d74f907e430dc77276b599bd7c517f58114e568840efd43ac7e0342b22e5d7ee

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