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()

# All equivalent formats; use of LangCodes is recommended
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("universe", 42)
except sk.LanguageCodeError as e:
    print(e)  # Invalid language code: '42'

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

CLI

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

The above example returns a result dictionary for the query "kivi" from Finnish to English, without the "translations" field and with an indent level of 2, and saves the result into a file called "result.json" at the current directory.
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.0.tar.gz (13.2 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.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sanakirja_org-1.1.0.tar.gz
  • Upload date:
  • Size: 13.2 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.0.tar.gz
Algorithm Hash digest
SHA256 b936f44df35759ea4ca1fa94c3bcde7eda4d274beaebba19081242534ba208ef
MD5 0f6a60328ef65ea64152eb653f105f5f
BLAKE2b-256 2662ea96d1a8e750719605d058bab26cd075706e836d9e043f171dcf1f007dd6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sanakirja_org-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7cd099dd5ad72825522e20df77c0f2c1c12abb215a2d882ca6497c9e9d0362a5
MD5 99e3ada88ea5ed1d69e17748488a760c
BLAKE2b-256 bc7c555afb2eb2a93bf9ca2b5d613ba32d9b79814fa394e0e3fe56a34bf96c49

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