SDKs overview

Detect Language offers a suite of Software Development Kits (SDKs) and client libraries designed to facilitate interaction with its Language Detection API. These SDKs encapsulate the underlying HTTP requests and responses, providing language-specific methods for common operations like detecting the language of a given text string or a batch of strings. The use of an SDK can streamline development by abstracting network communication, serialization, and error handling, allowing developers to focus on integrating language detection capabilities into their applications rather than managing the API's technical specifics.

The SDKs interact with a RESTful API, typically requiring an API key for authentication. This key is used to authorize requests and track usage against a developer's account, which may be subject to rate limits and quotas as outlined in the Detect Language pricing details. Developers can refer to the official Detect Language API documentation for detailed information on endpoints, request parameters, and response structures.

Official SDKs by language

Detect Language provides official SDKs for several popular programming languages, ensuring direct support and maintenance from the vendor. These libraries are generally recommended for their stability, active development, and adherence to API specifications. The official SDKs support key features of the Detect Language API, including single and batch language detection requests. The table below outlines the officially supported languages and their respective package names and installation commands.

Language Package Name Installation Command Maturity
Python detectlanguage pip install detectlanguage Stable
PHP detectlanguage/detectlanguage composer require detectlanguage/detectlanguage Stable
Ruby detectlanguage gem install detectlanguage Stable
Node.js detectlanguage npm install detectlanguage Stable
Java com.detectlanguage:detectlanguage Add to pom.xml (Maven) or build.gradle (Gradle) Stable
Go github.com/detectlanguage/detectlanguage-go go get github.com/detectlanguage/detectlanguage-go Stable

Installation

Installing a Detect Language SDK typically involves using a language-specific package manager. The process is designed to be straightforward, allowing developers to quickly add the library to their project dependencies. Below are detailed installation instructions for each supported language, referencing common package management tools.

Python

For Python, the pip package installer is used to fetch the detectlanguage library from PyPI. Ensure you have pip installed and updated.

pip install detectlanguage

For more advanced dependency management, Python developers might use tools like Pipenv or Poetry to manage virtual environments and project dependencies, ensuring consistency across development and production environments.

PHP

PHP projects typically use Composer for dependency management. The detectlanguage/detectlanguage package is available via Packagist.

composer require detectlanguage/detectlanguage

After installation, Composer generates an autoloader file (typically vendor/autoload.php) that must be included in your PHP script to use the library classes.

Ruby

Ruby developers use RubyGems to install libraries. The detectlanguage gem is available on RubyGems.org.

gem install detectlanguage

Once installed, you can require the gem in your Ruby application.

Node.js

For Node.js applications, npm (Node Package Manager) is the standard tool. The detectlanguage package is hosted on the npm registry.

npm install detectlanguage

Alternatively, if you prefer Yarn for package management:

yarn add detectlanguage

Java

Java projects primarily use Maven or Gradle for dependency management. You need to add the detectlanguage dependency to your project's build file.

Maven

Add the following to your pom.xml:

<dependencies>
    <dependency>
        <groupId>com.detectlanguage</groupId>
        <artifactId>detectlanguage</artifactId>
        <version>1.1.0</version> <!-- Use the latest version -->
    </dependency>
</dependencies>

Gradle

Add the following to your build.gradle:

dependencies {
    implementation 'com.detectlanguage:detectlanguage:1.1.0' // Use the latest version
}

Go

Go modules are used to manage dependencies in Go projects. The detectlanguage-go library is available on GitHub.

go get github.com/detectlanguage/detectlanguage-go

After running this, the dependency will be added to your go.mod file. You may then import it in your Go source files.

Quickstart example

This section provides a quickstart example demonstrating how to use the Detect Language Python SDK to detect the language of a text string. The examples for other languages follow a similar pattern, involving API key configuration and calling a detection method.

Python Quickstart

First, ensure you have your Detect Language API key. You can obtain a key by signing up on the Detect Language website.

import detectlanguage

# Configure your API key
detectlanguage.configuration.api_key = "YOUR_API_KEY"

# Or set it as an environment variable (recommended for production)
# import os
# detectlanguage.configuration.api_key = os.environ.get("DETECT_LANGUAGE_API_KEY")

# Detect language of a single string
text = "Hello world!"
detections = detectlanguage.simple_detect(text)
print(f"Detected language for '{text}': {detections}")

text_german = "Hallo Welt!"
detections_german = detectlanguage.simple_detect(text_german)
print(f"Detected language for '{text_german}': {detections_german}")

# Detect language of multiple strings (batch detection)
texts_batch = [
    "Where is the nearest ATM?",
    "¿Dónde está el cajero automático más cercano?",
    "Où est le distributeur automatique de billets le plus proche?"
]
batch_results = detectlanguage.detect(texts_batch)

for i, result in enumerate(batch_results):
    print(f"Original text: '{texts_batch[i]}'")
    for detection in result:
        print(f"  Language: {detection['language']}, Confidence: {detection['confidence']:.2f}, Is reliable: {detection['isReliable']}")

# Get account status
status = detectlanguage.get_status()
print(f"Account status - Detections remaining: {status['daily_requests_left']}, Plan: {status['plan']}")

This Python example initializes the API client with an API key, performs both single and batch language detections, and then retrieves the account's usage status. The simple_detect method returns only the primary language code, while detect provides a more detailed list of potential languages with confidence scores and reliability indicators.

Community libraries

While Detect Language provides official SDKs, the open-source community may also contribute unofficial client libraries or wrappers. These community-driven projects can sometimes offer support for niche programming languages, specific frameworks, or alternative feature sets not covered by the official offerings. However, community libraries typically do not come with the same level of vendor support or guarantee of compatibility with future API changes. Developers should evaluate the maintenance status, community activity, and documentation of any unofficial library before integrating it into production systems.

To find community libraries, developers often search package repositories specific to their programming language (e.g., PyPI for Python, npm for Node.js, or GitHub for general-purpose repositories) using keywords like "Detect Language" or "language detection." When considering a community library, it is advisable to review its source code, check for recent updates, and read user reviews or issue trackers to assess its reliability and feature completeness. The Detect Language official documentation focuses primarily on its own SDKs and direct API interaction, so external searches are typically required to discover community-contributed tools.

For example, while not directly related to Detect Language, the broader landscape of natural language processing libraries includes tools like NLTK in Python, which offers various linguistic processing capabilities, as described in the Google Machine Learning Glossary entry on Natural Language Processing. Developers needing more extensive NLP features beyond simple language detection might integrate Detect Language with such broader NLP frameworks.