Skip to main content

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

Project description

sanakirja-org

License 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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: sanakirja_org-1.0.0.tar.gz
  • Upload date:
  • Size: 11.8 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.tar.gz
Algorithm Hash digest
SHA256 d0e504033b4d5efe256e02fc48c4186c78f1a3fab6a127b209ead767e5aecac6
MD5 971d4069b025395a812fd9a26d8fd7f1
BLAKE2b-256 43a5b74e3307d904d1dcc9947cb81d5755b9960794fe583a4a42f3dffbaa58b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sanakirja_org-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f5f02b06bbba391044d943fea9900a53c3a6ae4662dc4de79809025ee675b4c
MD5 b3eb269bbb7d4afd346b2390675e394c
BLAKE2b-256 d5539a25c6a51cee03eb9205e4578e667fe7fdb53577b8c71115df6a0bc32cff

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