Skip to main content

An unofficial Python API and CLI tool for sanakirja.org.

Project description

sanakirja-org

LicenseCC BY-SA 3.0 GitHubStars PyPI BuyMeACoffee

An unofficial Python API and CLI tool for sanakirja.org.

Installation

pip install sanakirja-org

Examples

Language codes

import sanakirja as sk

sanakirja = sk.Sanakirja()

# The below formats are all equivalent
sanakirja.search(q="life", l=sk.LangCodes.en)
sanakirja.search(q="life", l="en")
sanakirja.search(q="life", l=3)

Basic search

import sanakirja as sk

sanakirja = sk.Sanakirja()

# No language codes specified -> source language is guessed and simple translations are provided for each language
sanakirja.search(q="everything")

# No target language code specified -> simple translations are provided from the source language to each language
sanakirja.search(q="everything", l=sk.LangCodes.en)

# No source language code specified -> source language is guessed and accurate translations are provided for the target language
sanakirja.search(q="everything", l2=sk.LangCodes.fi)

# Both language codes specified -> accurate translations are provided from the source language to the target language
sanakirja.search(q="everything", l=sk.LangCodes.en, l2=sk.LangCodes.fi)

Error handling

import sanakirja as sk

sanakirja = sk.Sanakirja()

try:
    sk_res = sanakirja.search(q="universe", l=42)
except sk.LanguageCodeError as e:
    print(e)  # Invalid language code: '42'

[!TIP] Valid language codes can be viewed, for example, via the __members__ attribute of the LangCodes IntEnum.

CLI

sanakirja --from fi --to 3 --lang sv --show="all,-translations" --pretty 2 --output "./result.json" kivi

The above example performs a search for the query "kivi" from Finnish to English. The language of user interface elements is set to Swedish, the "translations" field is omitted and the indent level is set to 2. Finally, the result is saved into a file named "result.json" at the current directory.

[!NOTE] The argument -h, --help provides more information about each argument.

Attribution and licensing

This package is licensed under the MIT License.

It makes use of content retrieved from sanakirja.org, a web service provided by Sanakirja.org Solutions Oy. The content is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License (CC BY-SA 3.0).
This package is not affiliated with or endorsed by sanakirja.org.

If you redistribute content fetched using this package, you are responsible for complying with the terms of the CC BY-SA license, including proper attribution.

Project details


Download files

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

Source Distribution

sanakirja_org-1.1.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

sanakirja_org-1.1.2-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file sanakirja_org-1.1.2.tar.gz.

File metadata

  • Download URL: sanakirja_org-1.1.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sanakirja_org-1.1.2.tar.gz
Algorithm Hash digest
SHA256 d0393ce2196efc7b442800d641c5da8f380e0119c95d6c17b2b33800b5f09b38
MD5 2465d5c049821c199176912a8ef96689
BLAKE2b-256 b5e17b79f74e448c8abfbe46df1c9859b985ec8fa9729799c0bc7618c680f626

See more details on using hashes here.

File details

Details for the file sanakirja_org-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: sanakirja_org-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sanakirja_org-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 292dff6261c45c5ed2f999475e724fb3ce834d512ed229de611b43c021ab4d09
MD5 0c60ee28bba1bb4798bb064c14414de4
BLAKE2b-256 ee721cf61249cbdffa574360840a1a4066dacab5f31b5164970b5a1b68173e9d

See more details on using hashes here.

Supported by

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