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.0.0.post1.tar.gz (12.3 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.0.0.post1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file sanakirja_org-1.0.0.post1.tar.gz.

File metadata

  • Download URL: sanakirja_org-1.0.0.post1.tar.gz
  • Upload date:
  • Size: 12.3 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.0.0.post1.tar.gz
Algorithm Hash digest
SHA256 324963628d5882877c1ba061e6d25a4f54ba3b51b102fa2d534926aa19da32e5
MD5 ff141e79551717e6081e47478aabd07a
BLAKE2b-256 d99fb235c44202b49603eb627aeff7ad13c87edf3c19f0abe3a499a7dd5822d9

See more details on using hashes here.

File details

Details for the file sanakirja_org-1.0.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for sanakirja_org-1.0.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 da66b71b6d900367c68acb450b3eda582c47ee5ccc07519cec9e2c12b8f75ffa
MD5 cd4a7ac8debff25748de1913b07903bc
BLAKE2b-256 be12415f1a5836fcb418719560d26dedbe82fa2727074949761f19be062d585c

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