Skip to main content

API wrapper for the language detection as a service Linguin AI.

Project description

PyPI version build

Linguin AI Python wrapper

This is a Python wrapper for the Linguin AI API (see API docs) providing Language Detection as a Service.

Linguin AI is free for up to 100 detections per day. You can get your API key here.

Installation

pip3 install linguin

Usage

Get started with just a few lines of code:

from linguin import Linguin

# go to https://linguin.ai to get your key
linguin = Linguin("YOUR_API_TOKEN")

response = linguin.detect("test")

response.is_success
# >> True

response.result
# >> {'results': [{ 'lang': 'en', confidence: 1.0 }, ...]}

If anything goes wrong for example: empty query string:

response = linguin.detect(" ")
    
response.is_success
# >> False
   
print(response.error)
# >> Error code: 400. The language of an empty text is more of a philosophical question.

response.error.status
# >> 400

response.error.message
# >> The language of an empty text is more of a philosophical question.

If you prefer to handle exceptions instead:

response = linguin.detect(" ", raise_on_error=True)
# >> raises LinguinInputError

See the list of all exceptions here.

Bulk detection

To detect the language of multiple texts with one API call, you can pass them as an array to the bulk method. The results will be returned in the same order as the texts. All texts have to not be empty.

response = linguin.bulk(["test", "Bahnhof", "고마워요"])

response.is_success
# >> True

response.result
# >> [{'results': [{'lang': 'en', 'confidence': 1.0}, ...]}, {...}, ...]

Account status

You can fetch the status of your account:

response = linguin.status()

response.result
# >> {'daily_limit': 50000, 'detections_today': 4500, 'remaining_today': 45500}
# for unlimited usage we return -1

Language list

You can fetch the list of supported languages:

from linguin import Linguin

languages = Linguin.languages()
# >> { 'de': ["German", "Deutsch"], ... }

Development

After checking out the repo, run pip3 install -r requirements.txt to install dependencies. Run tests with python3 -m unittest

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/LinguinAI/linguin-python. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Linguin project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

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

linguin-1.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

linguin-1.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: linguin-1.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.2

File hashes

Hashes for linguin-1.1.0.tar.gz
Algorithm Hash digest
SHA256 10d4dba73de43890a766803bc9b764e2a3c46415912f019d1eced4dce28a9fc0
MD5 4f1f9dfff505c99a317c791a65d3d421
BLAKE2b-256 6e2eaf3b53f8871862c82f5cdd4f2f2f9f73cac90534ccf7ffceb7249297d825

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linguin-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.2

File hashes

Hashes for linguin-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d18ee1d4447edd12097a6ba54d2f177c9ce419f3577bb4aece4b3a5edc7ed271
MD5 d314cf1af5d1ced3a7a4e2b4f84d50ad
BLAKE2b-256 db92510e715eb5fc5e3d7e8ad7650b15103c499e2044dbb4557e5e28adba8633

See more details on using hashes here.

Supported by

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