Registry / ai-ml / conllu

conllu

JSON →
library6.0.0pypypi✓ verified 90d ago

The `conllu` library (version 6.0.0) is a Python parser for the CoNLL-U format, converting CoNLL-U formatted strings into a nested Python dictionary structure. CoNLL-U is frequently used as an output format for natural language processing tasks. It is actively maintained with a moderate release cadence and has no external dependencies.

pip install conllu
INSTALL
IMPORT
SIG · CONLLU
C
conllu
ai-mlpythonv6.0.0
Install
1.5s avg
Import
17ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v6.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.018s · 17.9MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.017s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
✓ from conllu import parse
parse_tree
✓ from conllu import parse_tree

Parses a CoNLL-U formatted string into a list of `TokenList` objects, each representing a sentence. Tokens can be accessed as dictionary-like objects, and sentence metadata is available via the `.metadata` attribute.

from conllu import parse data = """ # text = The quick brown fox jumps over the lazy dog. 1 The the DET DT Definite=Def|PronType=Art 4 det _ _ 2 quick quick ADJ JJ Degree=Pos 4 amod _ _ 3 brown brown ADJ JJ Degree=Pos 4 amod _ _ 4 fox fox NOUN NN Number=Sing 5 nsubj _ _ 5 jumps jump VERB VBZ Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin 0 root _ _ 6 over over ADP IN _ 9 case _ _ 7 the the DET DT Definite=Def|PronType=Art 9 det _ _ 8 lazy lazy ADJ JJ Degree=Pos 9 amod _ _ 9 dog dog NOUN NN Number=Sing 5 nmod _ SpaceAfter=No 10 . . PUNCT . _ 5 punct _ _ """ sentences = parse(data) # Accessing tokens and metadata sentence = sentences[0] print(f"Sentence text: {sentence.metadata.get('text')}") for token in sentence: print(f"ID: {token['id']}, Form: {token['form']}, UPos: {token['upos']}")
Debug
Known issues
breakingVersion 5.0 (and newer, including 6.0.0) requires Python 3.8 or higher. Projects running on Python 3.6 or 3.7 must upgrade their Python version or pin `conllu` to a version older than 5.0.
fix
Upgrade to Python 3.8+ or pin `conllu<5.0.0`.
affects: >=5.0.0
gotchaIn version 3.0, the field names `xpostag` and `upostag` were changed to `xpos` and `upos` respectively, to align with Universal Dependencies 2.0. While `conllu` provides aliasing for backward compatibility, it's recommended to update code to use `xpos` and `upos` for clarity and future compatibility.
fix
Update token field access from `token['xpostag']` to `token['xpos']` and `token['upostag']` to `token['upos']`.
affects: >=3.0.0
breakingUpdating from very old versions (e.g., 0.1 to 1.0) involved significant breaking changes to the API. Users migrating from such old versions should consult the release notes for a comprehensive upgrade guide.
fix
Review the official migration guides for versions 0.1 to 1.0 on the PyPI project page or GitHub repository for detailed code changes required.
affects: 0.1.x to 1.x.x
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'conllu'
The `conllu` library has not been installed in your Python environment or the environment where your script is being run.
fix
Install the library using pip: `pip install conllu`
ValueError: Missing column at index X for token Y
This error occurs when the input CoNLL-U data does not strictly adhere to the expected 10-column format, or a line is malformed, preventing the parser from correctly extracting all fields for a token. The index `X` indicates which column was expected but not found.
fix
Inspect your CoNLL-U file around the indicated token or line to ensure it has exactly 10 tab-separated columns for each token line, blank lines for sentence boundaries, and comment lines starting with `#`. Ensure no lines are truncated or contain unexpected characters. For custom formats, consider using `conllu.parse(data, fields=...)` with a custom `fields` definition.
AttributeError: 'list' object has no attribute 'serialize'
The `conllu.parse()` function returns a list of `TokenList` objects when parsing multiple sentences. You are attempting to call the `.serialize()` method, which exists on a `TokenList` object, directly on the Python list containing these `TokenList` objects.
fix
Iterate through the list of `TokenList` objects and call `.serialize()` on each individual `TokenList`, or if you parsed a single sentence, access the first element: `sentences = parse(data)`; `sentence_string = sentences[0].serialize()`.
Upgrade
Version history
6.0.0latest on PyPI · released Oct 13, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
conllu — pip install conllu · libregistry