Skip to main content

This is tokenspeed-xgrammar, the TokenSpeed distribution of XGrammar. Install it with pip install tokenspeed-xgrammar; Python imports remain import xgrammar. Do not install it alongside the upstream xgrammar distribution: both own the same import package. Python and native C++ consumers must use matching versions of the wheel and source distribution.

XGrammar

Documentation License PyPI PyPI Downloads Ask DeepWiki

Efficient, Flexible and Portable Structured Generation

Get Started | Documentation | Blogpost | Technical Report

News

  • [2026/5] XGrammar-2 has been released! Check out our blog for more information.
  • [2025/12] XGrammar has been officially integrated into Mirai
  • [2025/09] XGrammar has been officially integrated into OpenVINO GenAI
  • [2025/02] XGrammar has been officially integrated into Modular's MAX
  • [2025/01] XGrammar has been officially integrated into TensorRT-LLM.
  • [2024/12] XGrammar has been officially integrated into vLLM.
  • [2024/12] We presented research talks on XGrammar at CMU, UC Berkeley, MIT, THU, SJTU, Ant Group, LMSys, Qingke AI, Camel AI. The slides can be found here.
  • [2024/11] XGrammar has been officially integrated into SGLang.
  • [2024/11] XGrammar has been officially integrated into MLC-LLM.
  • [2024/11] We officially released XGrammar v0.1.0!

Overview

XGrammar is an open-source library for efficient, flexible, and portable structured generation.

It leverages constrained decoding to ensure 100% structural correctness of the output. It supports general context-free grammar to enable a broad range of structures, including JSON, regex, custom context-free grammar, etc.

XGrammar uses careful optimizations to achieve extremely low overhead in structured generation. It has achieved near-zero overhead in JSON generation, making it one of the fastest structured generation engines available.

XGrammar features universal deployment. It supports:

  • Platforms: Linux, macOS, Windows
  • Hardware: CPU, NVIDIA GPU, AMD GPU, Apple Silicon, TPU, etc.
  • Languages: Python, C++, JavaScript, and Swift APIs
  • Models: Qwen, Llama, DeepSeek, Phi, Gemma, etc.

XGrammar is very easy to integrate with LLM inference engines. It is the default structured generation backend for most LLM inference engines, including vLLM, SGLang, TensorRT-LLM, and MLC-LLM, as well as many other companies. You can also try out their structured generation modes!

Get Started

Install XGrammar:

pip install xgrammar

For use with MPS on Apple Silicon, install with:

pip install "xgrammar[metal]"

Import XGrammar:

import xgrammar as xgr

Please visit our documentation to get started with XGrammar.

Contributing and governance

We welcome contributions of code, tests, documentation, bug reports, and reviews. See CONTRIBUTING.md to get started. All participants are expected to follow our Code of Conduct.

GOVERNANCE.md describes the current maintainers, technical decision process, and maintainer role changes. CODEOWNERS lists the reviewers responsible for specific parts of the repository.

Releases

XGrammar publishes versioned releases on GitHub Releases and Python packages on PyPI. Releases are made as needed when features, bug fixes, or compatibility updates are ready, without a fixed calendar schedule. Prereleases are identified separately from stable releases.

For each release, a maintainer selects a reviewed commit from main and coordinates the following:

  1. Verify that the applicable automated tests and package builds pass for the release commit, and resolve failures that affect the release.
  2. Prepare release notes describing features, fixes, compatibility changes, and known limitations.
  3. Tag the release commit and publish a GitHub release. The package workflow builds wheels and a source distribution and publishes them to PyPI when the GitHub release is published. Maintainers can also invoke that workflow manually.
  4. Check that the published packages and release notes are available, and follow up on reported regressions with fixes or a subsequent release.

The Python package version is generated from Git tags by setuptools-scm; no manual version update in pyproject.toml is needed. For example, v0.2.7 builds as 0.2.7, and commits after a release get development versions. Builds from Git need full history and tags; published source distributions retain their version without Git. To publish manually, run the package workflow on a release tag; manual branch runs only build artifacts.

Third-Party Bindings

  • Rust: xgrammar-rs — Community Rust bindings for XGrammar.

Collaborators

XGrammar has been widely adopted in industry, open-source projects, and academia. Our collaborators include:

                      WebLLM  

Citation

If you find XGrammar useful in your research, please consider citing our papers:

@article{dong2024xgrammar,
  title={Xgrammar: Flexible and efficient structured generation engine for large language models},
  author={Dong, Yixin and Ruan, Charlie F and Cai, Yaxing and Lai, Ruihang and Xu, Ziyi and Zhao, Yilong and Chen, Tianqi},
  journal={Proceedings of Machine Learning and Systems 7},
  year={2024}
}
@inproceedings{10.1145/3786335.3813124,
  author = {Li, Linzhang and Dong, Yixin and Wang, Guanjie and Xu, Ziyi and Jiang, Alexander and Chen, Tianqi},
  title = {XGrammar-2: Dynamic and Efficient Structured Generation Engine for Agentic LLMs},
  year = {2026},
  isbn = {9798400724152},
  publisher = {Association for Computing Machinery},
  address = {New York, NY, USA},
  url = {https://doi.org/10.1145/3786335.3813124},
  booktitle = {Proceedings of the ACM Conference on AI and Agentic Systems},
  pages = {1009--1022},
  numpages = {14}
}

Metadata

Release files for tokenspeed-xgrammar 0.2.9.post20261125

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

Source distribution (sdist)

Source distribution for tokenspeed-xgrammar 0.2.9.post20261125
File Size Uploaded Provenance Actions
tokenspeed_xgrammar-0.2.9.post20261125.tar.gz 2.8 MB Without provenance Details for tokenspeed_xgrammar-0.2.9.post20261125.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tokenspeed-xgrammar 0.2.9.post20261125
File Actions
tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details for tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Total release size: 13.3 MB

Release files / tokenspeed_xgrammar-0.2.9.post20261125.tar.gz

Download URL tokenspeed_xgrammar-0.2.9.post20261125.tar.gz
Size 2.8 MB
Tags Source
SHA-256 checksum
How to use checksums
ac14d53fcc509b663b617708ef2d213f32d6c5d32eedf90de0602a8bcbb4b338
BLAKE2b-256 checksum
How to use checksums
6f11871e03e361459a337d11d335a4d43c4c824308fc8379960fff6b4662a52c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.4 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4647d5d5b9e1bf3abb0b424aae9bef64297e6515e6f7f84567ab3faef1a2f19c
BLAKE2b-256 checksum
How to use checksums
6d86cf2f197ba98b21fa352eb210e2843a2a69be815807bb04bba10db633f0cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 1.2 MB
Tags CPython 3.13 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
bd844c79fde33cc6bbe9eefc9d4cfdf0085b2b2f640bcc6e2abaa7c4f9316f17
BLAKE2b-256 checksum
How to use checksums
c65bd09085de7b29408e6d7e3f87dd9903880a8e2e72c76ccc6f6a7a425c02b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.4 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f213614ff23109ff12dc0ff8a733e5bc7c424f2a232665a5e7d684ab5903002e
BLAKE2b-256 checksum
How to use checksums
dd7e2a48a5954364e730496a4147880ff815879b9f8668be86c8525a7b38c05e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
b07ed4d6e462aed100a33dd5c8f01858a197df61895d7eb43ba449c7b8aa11e7
BLAKE2b-256 checksum
How to use checksums
23ee51ff9696f76f310e494c1dd8c1f92ee75e4be345ed4b323c16bfe7a8736d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.4 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
81fe8a91744a1b4864980f4b56637bf7b37c172a7a937bb75e614a7262e0ba66
BLAKE2b-256 checksum
How to use checksums
f9f6be46e08000a1f81e066b708b859643e98d656d8bb5299c4a32d2b92d5748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
69aca238c56f5dcdce19acb7a2e488237c06a24c0aaa98ea9f37e482bf1c22c0
BLAKE2b-256 checksum
How to use checksums
f4cb7158f207013389f7eda4469ea79cc97ffd6e0633c4514281aaec3e78d3d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
96abb21e28132b0bf484e5cdf53dee3530c17bcf9b7ca73cb4e18ffca28eafb1
BLAKE2b-256 checksum
How to use checksums
65c16c999e0578cd4d76ff2d66089302db717dbf7875e2dca78a6bcb26900d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL tokenspeed_xgrammar-0.2.9.post20261125-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
ca6758588a049abdcaf76696487189e97816d8528832246b52158ae87129980d
BLAKE2b-256 checksum
How to use checksums
4eb03abfa7ae992633d76a4ee6598ed1073e03850ff49a47802fc2066097e27b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tokenspeed-xgrammar 0.2.9.post20261125

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.

Release history Release notifications | RSS feed

This release
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