Skip to main content

A natural language parser for Icelandic

Project description

A fast, efficient natural language processor for Icelandic


Greynir is a Python 3 (>= 3.7) package, published by Miðeind ehf., for working with Icelandic natural language text. Greynir can parse text into sentence trees, find lemmas, inflect noun phrases, assign part-of-speech tags and much more.

Greynir’s sentence trees can inter alia be used to extract information from text, for instance about people, titles, entities, facts, actions and opinions.

Full documentation for Greynir is available here.

Greynir is the engine of, a natural-language front end for a database of over 10 million sentences parsed from Icelandic news articles, and Embla, a voice-driven virtual assistant app for smart devices such as iOS and Android phones.

Greynir includes a hand-written context-free grammar for the Icelandic language, consisting of over 7,000 lines of grammatical productions in extended Backus-Naur format. Its fast C++ parser core is able to cope with long and ambiguous sentences, using an Earley-type parser as enhanced by Scott and Johnstone.

Greynir employs the Tokenizer package, by the same authors, to tokenize text, and uses BinPackage as its database of Icelandic vocabulary and morphology.


Use Greynir to easily inflect noun phrases:

from reynir import NounPhrase as Nl

# Create a NounPhrase ('nafnliður') object
karfa = Nl("þrír lúxus-miðar á Star Wars og tveir brimsaltir pokar af poppi")

# Print the NounPhrase in the correct case for each context
# (þf=þolfall/accusative, þgf=þágufall/dative). Note that
# the NounPhrase class implements __format__(), allowing you
# to use the case as a format specification, for instance in f-strings.

print(f"Þú keyptir {karfa:þf}.")
print(f"Hér er kvittunin þín fyrir {karfa:þgf}.")

The program outputs the following text, correctly inflected:

Þú keyptir þrjá lúxus-miða á Star Wars og tvo brimsalta poka af poppi.
Hér er kvittunin þín fyrir þremur lúxus-miðum á Star Wars og tveimur brimsöltum pokum af poppi.

Use Greynir to parse a sentence:

>>> from reynir import Greynir
>>> g = Greynir()
>>> sent = g.parse_single("Ása sá sól.")
>>> print(sent.tree.view)
P                               # Root
+-S-MAIN                        # Main sentence
  +-IP                          # Inflected phrase
    +-NP-SUBJ                   # Noun phrase, subject
      +-no_et_nf_kvk: 'Ása'     # Noun, singular, nominative, feminine
    +-VP                        # Verb phrase containing arguments
      +-VP                      # Verb phrase containing verb
        +-so_1_þf_et_p3: 'sá'   # Verb, 1 accusative arg, singular, 3rd p
      +-NP-OBJ                  # Noun phrase, object
        +-no_et_þf_kvk: 'sól'   # Noun, singular, accusative, feminine
+-'.'                           # Punctuation
>>> sent.tree.nouns
['Ása', 'sól']
>>> sent.tree.verbs
>>> sent.tree.flat
'P S-MAIN IP NP-SUBJ no_et_nf_kvk /NP-SUBJ VP so_1_þf_et_p3
    NP-OBJ no_et_þf_kvk /NP-OBJ /VP /IP /S-MAIN p /P'
>>> # The subject noun phrase (S.IP.NP also works)
>>> sent.tree.S.IP.NP_SUBJ.lemmas
>>> # The verb phrase
>>> sent.tree.S.IP.VP.lemmas
['sjá', 'sól']
>>> # The object within the verb phrase (S.IP.VP.NP also works)
>>> sent.tree.S.IP.VP.NP_OBJ.lemmas


This package runs on CPython 3.7 or newer, and on PyPy 3.7 or newer.

To find out which version of Python you have, enter:

$ python --version

If a binary wheel package isn’t available on PyPi for your system, you may need to have the python3-dev package (or its Windows equivalent) installed on your system to set up Greynir successfully. This is because a source distribution install requires a C++ compiler and linker:

$ # Debian or Ubuntu:
$ sudo apt-get install python3-dev

Depending on your system, you may also need to install libffi-dev:

$ # Debian or Ubuntu
$ sudo apt-get install libffi-dev


To install this package, assuming Python 3 is your default Python:

$ pip install reynir

If you have git installed and want to be able to edit the source, do like so:

$ git clone
$ cd GreynirPackage
$ # [ Activate your virtualenv here if you have one ]
$ pip install -e .

The package source code is now in GreynirPackage/src/reynir.


To run the built-in tests, install pytest, cd to your GreynirPackage subdirectory (and optionally activate your virtualenv), then run:

$ python -m pytest


A parsing test pipeline for different parsing schemas, including the Greynir schema, has been developed. It is available here.


Please consult Greynir’s documentation for detailed installation instructions, a quickstart guide, and reference information, as well as important information about copyright and licensing.

Download files

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

Source Distribution

reynir-3.5.3.tar.gz (553.2 kB view hashes)

Uploaded source

Built Distributions

reynir-3.5.3-pp39-pypy39_pp73-win_amd64.whl (424.8 kB view hashes)

Uploaded pp39

reynir-3.5.3-pp38-pypy38_pp73-win_amd64.whl (424.8 kB view hashes)

Uploaded pp38

reynir-3.5.3-pp37-pypy37_pp73-win_amd64.whl (424.8 kB view hashes)

Uploaded pp37

reynir-3.5.3-cp311-cp311-win_amd64.whl (427.2 kB view hashes)

Uploaded cp311

reynir-3.5.3-cp311-cp311-macosx_11_0_arm64.whl (429.9 kB view hashes)

Uploaded cp311

reynir-3.5.3-cp311-cp311-macosx_10_9_x86_64.whl (429.2 kB view hashes)

Uploaded cp311

reynir-3.5.3-cp310-cp310-win_amd64.whl (427.2 kB view hashes)

Uploaded cp310

reynir-3.5.3-cp310-cp310-macosx_11_0_arm64.whl (429.9 kB view hashes)

Uploaded cp310

reynir-3.5.3-cp310-cp310-macosx_10_9_x86_64.whl (429.2 kB view hashes)

Uploaded cp310

reynir-3.5.3-cp39-cp39-win_amd64.whl (427.2 kB view hashes)

Uploaded cp39

reynir-3.5.3-cp39-cp39-macosx_11_0_arm64.whl (429.9 kB view hashes)

Uploaded cp39

reynir-3.5.3-cp39-cp39-macosx_10_9_x86_64.whl (429.2 kB view hashes)

Uploaded cp39

reynir-3.5.3-cp38-cp38-win_amd64.whl (427.2 kB view hashes)

Uploaded cp38

reynir-3.5.3-cp38-cp38-macosx_11_0_arm64.whl (429.8 kB view hashes)

Uploaded cp38

reynir-3.5.3-cp38-cp38-macosx_10_9_x86_64.whl (429.2 kB view hashes)

Uploaded cp38

reynir-3.5.3-cp37-cp37m-win_amd64.whl (427.2 kB view hashes)

Uploaded cp37

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page