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.1.tar.gz (13.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.1.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sanakirja_org-1.1.1.tar.gz
  • Upload date:
  • Size: 13.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.1.1.tar.gz
Algorithm Hash digest
SHA256 16051ad21c4dba586ec7a7c7024c6021cca91cc82e46b74deeb41f7095776e67
MD5 a0562aa134483e2a5c49b8b335792a79
BLAKE2b-256 8ad871d42b9b1a3342121d6686d17353010fd162e165d426d1a86fbcd0171dde

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sanakirja_org-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b254c8c15a2f68ce9295e85a06839182b52f85a03dc7aefd13b44302170590b5
MD5 2b9e924ae66e777dcca92a079257afa2
BLAKE2b-256 f0e895b371f32ea172c1a60beca37425724c3a2f5f93b403692426e8076cbbad

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