Skip to main content

License: MIT Python 3.10 Release PyPI Build

Greynir

GreynirEngine

A fast, efficient natural language processing engine for Icelandic

Overview

Greynir is a Python 3 (>=3.10) 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 Greynir.is, 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.

Examples

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
['sjá']
>>> 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
['Ása']
>>> # 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
['sól']

Extracting lemmas and POS tags for web display

Greynir preserves the original text of each token, including surrounding whitespace. This allows you to reconstruct the exact original input while annotating it with linguistic information such as lemmas and part-of-speech (POS) tags.

from reynir import Greynir

g = Greynir()
sent = g.parse_single("Ása   sá   sól.")

# Build a map from token index to terminal node
terminal_map = {node.index: node for node in sent.terminal_nodes}

html_parts = []
for i, tok in enumerate(sent.tokens):
    # tok.original preserves the original text with spacing
    original = tok.original or ""
    if i in terminal_map:
        node = terminal_map[i]
        # Wrap with linguistic info (lemma and POS tag)
        html_parts.append(
            f'<span data-lemma="{node.lemma}" data-pos="{node.tcat}">'
            f'{original}</span>'
        )
    else:
        html_parts.append(original)

html = "".join(html_parts)
print(html)

The program outputs the following HTML, with the original spacing preserved and each token annotated with its lemma and POS tag (no=noun, so=verb):

<span data-lemma="Ása" data-pos="no">Ása</span><span data-lemma="sjá" data-pos="so"></span><span data-lemma="sól" data-pos="no">   sól</span><span data-lemma="." data-pos="">.</span>

Prerequisites

This package runs on CPython 3.10 or newer, and on PyPy 3.11 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

Installation

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 https://github.com/mideind/GreynirEngine
cd GreynirEngine
# [ Activate your virtualenv here if you have one ]
pip install -e .

The package source code is in GreynirEngine/src/reynir.

Tests

To run the built-in tests, cd to your GreynirEngine subdirectory and, using uv, run:

uv sync
uv run pytest

Alternatively, install pytest into your virtualenv and run python -m pytest.

Evaluation

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

Documentation

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

Troubleshooting

GreynirEngine uses a lock file, located alongside the binary grammar file within the package directory (reynir/Greynir.grammar.bin.lock), to serialize the (re)generation of the binary grammar between processes. If a process gets stuck holding the lock, parser initialization fails after a timeout with an error message identifying the lock file. Terminate the process holding the lock, or - if no such process exists - delete the lock file named in the error message, and try again.

Copyright and licensing

Greynir is Copyright © 2016-2025 by Miðeind ehf.. The original author of this software is Vilhjálmur Þorsteinsson.

Miðeind ehf.

This software is licensed under the MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

If you would like to use this software in ways that are incompatible with the standard MIT license, contact Miðeind ehf. to negotiate custom arrangements.


GreynirEngine indirectly embeds the Database of Icelandic Morphology, (Beygingarlýsing íslensks nútímamáls), abbreviated BÍN. GreynirEngine does not claim any endorsement by the BÍN authors or copyright holders.

The BÍN source data are publicly available under the CC BY-SA 4.0 license, as further detailed here in English and here in Icelandic.

In accordance with the BÍN license terms, credit is hereby given as follows:

Beygingarlýsing íslensks nútímamáls. Stofnun Árna Magnússonar í íslenskum fræðum. Höfundur og ritstjóri Kristín Bjarnadóttir.

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.7.2.tar.gz (441.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

reynir-3.7.2-pp311-pypy311_pp73-win_amd64.whl (465.2 kB view details)

Uploaded PyPyWindows x86-64

reynir-3.7.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (442.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

reynir-3.7.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl (438.5 kB view details)

Uploaded PyPymacOS 11.0+ ARM64

reynir-3.7.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl (438.0 kB view details)

Uploaded PyPymacOS 10.15+ x86-64

reynir-3.7.2-cp310-abi3-win_amd64.whl (440.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

reynir-3.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (513.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

reynir-3.7.2-cp310-abi3-macosx_11_0_arm64.whl (444.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

reynir-3.7.2-cp310-abi3-macosx_10_9_x86_64.whl (444.8 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file reynir-3.7.2.tar.gz.

File metadata

  • Download URL: reynir-3.7.2.tar.gz
  • Upload date:
  • Size: 441.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reynir-3.7.2.tar.gz
Algorithm Hash digest
SHA256 6243de7c6d5b2554652fd118838c874da7db86e4575488746b7f84669e416fb3
MD5 329d379678be028f496b679e694c323b
BLAKE2b-256 2408b0c190a6f2efca41131d2ae6df6dfc11ff67d59807a8da3e5264a5eff8fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2.tar.gz:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-pp311-pypy311_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-pp311-pypy311_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 b9f8389e16e00eca040dea47afa8f56544f4f5c51ca90cf6821c898d17933606
MD5 6e2d48f20a391f81d7b3d6997c02aeb1
BLAKE2b-256 7d0229c4938bab97d3beb678fb25670eaabe627871095ab10b7133f842e46099

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-pp311-pypy311_pp73-win_amd64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7fe1ed301c3546df12f84f1222c51ab399e62b713ca6d40bf1a272579a5c777c
MD5 b53c8883670c3122cc9d92330714baf3
BLAKE2b-256 c4221644277959cf1776d265988be9f7dbd36c5dc3569c96158f2cc62dc4101d

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 78ed13d5bbb50e5c18fcbf531d301c500336257b7363e1d6456e43e253faf016
MD5 40bdb0d9f13c29799502def4c23fedf1
BLAKE2b-256 d8197d107d1842b3844760112d0e13969332358ec9953329e7519523b8e68608

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2f587684cb9b61a378c316b997f4b9c5195d83c12cfbc1d35f279095692842d4
MD5 1945369bccc8cef42204c9a564d1fc58
BLAKE2b-256 a6817673a6832dde53e7995c0bd37ff39d54b9058b90acade07391f0449d492c

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: reynir-3.7.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 440.6 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reynir-3.7.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 60342658ce4428f60225744d74296ab1057ef5eefb3df39909496cd194bafbeb
MD5 7638e6bd8a8f24e1801e115163dafc55
BLAKE2b-256 ef3fdd068e72220778e84c2ac5b3b2a5b4b6870aed2d8479cfe68976f4da1a55

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-cp310-abi3-win_amd64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4fcef451ee0ae913cb7c6bba9822b89603b3b024d7e34c431a44a9db051a41ee
MD5 201666a1e5a1c9a0922086e0f736693a
BLAKE2b-256 b100119ec5a97d84a4c1cc825d904da0334ba1ac22a2b5070a248930c4916857

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5c9efe174ccaf093570c92e36a9cb1a59312cd670260c711e0856486753d170
MD5 14e53a6230aa0fed5b0ea8f1d4882e50
BLAKE2b-256 ec2e63b42f85e8269df776b53538fabe47306fbd8e82e6339fdbe7277e82f01f

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.7.2-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.7.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0e4462df4548a4a8faa3310ac9e5b5a609a903a0c98aab679600f966465d0f8b
MD5 758c8138c947a47836f34013ac17e668
BLAKE2b-256 428f2f3e47faac39150321ebcb1a863b6dbadad511c7370dc7b573cd11a97406

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.7.2-cp310-abi3-macosx_10_9_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page