polars-corpus
Corpus linguistics functions for Polars: search, concordances, frequency lists, collocations, keywords, dispersion, and lexical diversity. The query matcher is written in Rust; the rest is Python over Polars expressions.
A corpus is a DataFrame (or LazyFrame) with one row per token. The default
column names are token, pos, lemma and file_id; every function that
reads one of these takes a *_column or expr argument to point it elsewhere.
A LazyFrame is searched a chunk of files at a time, so the corpus does not have
to fit in memory.
The package is at version 0.2.0 and the API may still change.
Documentation: https://rmalouf.github.io/polars_corpus/
Installation
pip install polars-corpus
The plotting functions need matplotlib, which is in the examples extra:
pip install "polars-corpus[examples]"
Requires Python 3.11 or later and Polars 1.36 or later, including 2.0.
Usage
import nltk
import polars as pl
import polars_corpus as plc
nltk.download("brown")
corpus = plc.from_nltk(nltk.corpus.brown) # token, pos, sentence_tag, file_id, category
# Simple (BNCweb-style) query: "small" followed by a noun
results = plc.search(corpus, "small _{SUBST}")
results.concordance("token", window=5)
# CQP query
plc.search_cqp(corpus, '[pos="JJ"] [token="(?i)house"]').concordance(window=2)
word = pl.col("token").str.to_lowercase()
plc.frequency_list(corpus, word)
plc.collocations(plc.search(corpus, "house"), word, "logdice")
plc.keywords(
corpus.filter(pl.col("category") == "news"),
corpus.filter(pl.col("category") != "news"),
word,
"ll",
)
plc.dispersion(corpus, word, ["range", "dp"])
The same functions are available through a .corpus namespace on DataFrames,
LazyFrames and expressions:
corpus.corpus.search("america").concordance("token", window=2)
Contents
- Search:
search(Simple query language) andsearch_cqp(CQP), with variable bindings in both. Results give KWIC concordances, hit distributions across a metadata column, and an interactive concordance viewer for Jupyter. - Frequency:
frequency_list,ngrams,crosstab. - Association measures: PMI, MI3, log-Dice, t-score, z-score,
log-likelihood, chi-squared, minimum sensitivity, simple maths, BIC, log
ratio, %DIFF, odds ratio, Welch's t-test. Used by
collocationsandkeywords. - Dispersion: range, SD, CV, Juilland's D, Gries's DP, Burch's DA.
- Lexical diversity: TTR, MSTTR, MTLD, Yule's K, vocabulary growth, frequency spectrum.
- Input: plain text and WLP files (gzip or zstd compressed), NLTK corpus readers, and the BNC XML edition.
- Plots:
barcode_plot,dispersion_plot,keyword_plot.
Not yet implemented: proximity operators (<<3>>, <<s>>) in the Simple query
language.
Query languages
- Simple:
small _{SUBST},( small | little ) _N*. See docs/simple_query.md. - CQP:
[pos="JJ"] [lemma="house"]. See docs/cqp_query.md.
Examples
Worked notebooks are in docs/notebooks/ and rendered on the documentation site: frequencies, concordances, collocations, keywords, dispersion, and vocabulary.
Development
Building from source needs a Rust toolchain and maturin:
make develop # build the extension into the active environment
pytest
License
MIT
Metadata
Release files for polars-corpus 0.2.1
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 |
|---|---|---|---|---|
| polars_corpus-0.2.1.tar.gz | 183.9 kB | With provenance | Details for polars_corpus-0.2.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| polars_corpus-0.2.1-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for polars_corpus-0.2.1-cp311-abi3-win_amd64.whl |
| polars_corpus-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for polars_corpus-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| polars_corpus-0.2.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for polars_corpus-0.2.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| polars_corpus-0.2.1-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for polars_corpus-0.2.1-cp311-abi3-macosx_11_0_arm64.whl |
| polars_corpus-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for polars_corpus-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 32.4 MB
Release files / polars_corpus-0.2.1.tar.gz
| Download URL | polars_corpus-0.2.1.tar.gz |
|---|---|
| Size | 183.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc0fa5a7c2668d67a15419a63372addd171e50cc2b6fae7a1162f1f88d5f31d8
|
|
BLAKE2b-256 checksum How to use checksums |
f4f85f46332b07cfe035353e9529b66a4f83a2cdef284b7dffd02bac371bf736
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / polars_corpus-0.2.1-cp311-abi3-win_amd64.whl
| Download URL | polars_corpus-0.2.1-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6cb7991cae62f4df639cf3b0c8c9df4c7f9e5ef68ae8d12e77f5cd9fbcefff0c
|
|
BLAKE2b-256 checksum How to use checksums |
ac21ba8e8941b4fa80cec47cca3adc191aa699f23a242ae540f840fe5ec5dfdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / polars_corpus-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | polars_corpus-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.6 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5e53d9853aa86bfbaa1650e87ebfa609e0b40a4fcdf7a42a20911eaf1d9b0b25
|
|
BLAKE2b-256 checksum How to use checksums |
541eb3cde97a5044cf9c24a22e98cbe882d2906533d78464e3d22bb80481d77f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / polars_corpus-0.2.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | polars_corpus-0.2.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0c13ab5b26e153ac4704f3b681a4c4ad4d36d6ec85ec00e8e54255e65ac09ac9
|
|
BLAKE2b-256 checksum How to use checksums |
6ba7fdbe7df03bcc5cb7f02543b06eb0e37f41cb51356f210f3d8cbb1fa2a7aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / polars_corpus-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | polars_corpus-0.2.1-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
76d4a60a3897941c1173f9bb5ef57e9e44b5c462e4a7c1a0d3209ed663d59917
|
|
BLAKE2b-256 checksum How to use checksums |
1576483cd1f1dc7c47638cb6a8e3e8ec29cf428056e23acf37befcab8998d81c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / polars_corpus-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | polars_corpus-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 6.4 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
6b97f44faa8904f5924e832d4d40bf0f636dede8eb757ffae0c186b148fa8849
|
|
BLAKE2b-256 checksum How to use checksums |
50e54575b554b36f55250a56a729a72a547378a835b0ba3888d004bfabbf66cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for polars-corpus 0.2.1
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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for polars_corpus-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA 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.