Skip to main content

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_language("test")

response.is_success
# >> True

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

response = linguin.detect_profanity("you moron")

response.is_success
# >> True

response.result
# >> {'score':  0.9981}

If anything goes wrong for example: empty query string:

response = linguin.detect_language(" ")
    
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_language(" ", 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_detect_language method. The results will be returned in the same order as the texts. All texts have to not be empty.

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

response.is_success
# >> True

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

To check multiple texts for profanity with one API call, you can pass them as an array to the bulk_detect_profanity method. The results will be returned in the same order as the texts. All texts have to not be empty.

response = linguin.bulk_detect_profanity(["a test", "you are a moron"])

response.is_success
# >> True

response.result
# >> {'scores': [0.0124, 0.9981]}

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.

Metadata

Release files for linguin 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linguin 2.0.0
File Size Uploaded
linguin-2.0.0.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for linguin 2.0.0
File Interpreter ABI Platform
linguin-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / linguin-2.0.0.tar.gz

Download URL linguin-2.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
877d5eb93069ef085670a64b40ac89347c8a73c1dcd8902ffb622f2694fb54bf
BLAKE2b-256 checksum
How to use checksums
9d804373afad1d660b8790af0a1fb2abd26e127aa8537189e67622f8f6e6d7cc
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / linguin-2.0.0-py3-none-any.whl

Download URL linguin-2.0.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
820517048b60ce3ddda50c1b5418e51f0c4b5586aea1abe7cdf954442bb95a04
BLAKE2b-256 checksum
How to use checksums
c0624d560378a3919ebf1cf8c2a45d70be50635f3cd286d512459a10cc873900
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page