Lexicala.NET
3.2.0-beta.2
dotnet add package Lexicala.NET --version 3.2.0-beta.2
NuGet\Install-Package Lexicala.NET -Version 3.2.0-beta.2
<PackageReference Include="Lexicala.NET" Version="3.2.0-beta.2" />
<PackageVersion Include="Lexicala.NET" Version="3.2.0-beta.2" />
<PackageReference Include="Lexicala.NET" />
paket add Lexicala.NET --version 3.2.0-beta.2
#r "nuget: Lexicala.NET, 3.2.0-beta.2"
#:package Lexicala.NET@3.2.0-beta.2
#addin nuget:?package=Lexicala.NET&version=3.2.0-beta.2&prerelease
#tool nuget:?package=Lexicala.NET&version=3.2.0-beta.2&prerelease
Lexicala.NET
A modern .NET client library for the Lexicala Dictionary API. Lexicala provides comprehensive linguistic data including translations, definitions, pronunciations, and more across multiple languages.
Prerequisites
- .NET 8.0 or .NET 10.0 runtime
- A RapidAPI account with an API key for Lexicala (sign up at RapidAPI)
Installation
Install the package via NuGet:
dotnet add package Lexicala.NET
Or using the Package Manager Console:
Install-Package Lexicala.NET
Configuration
1. Obtain API Key
- Sign up for a RapidAPI account at rapidapi.com
- Subscribe to the Lexicala API
- Copy your API key from the RapidAPI dashboard
2. Configure Your Application
Add the Lexicala configuration to your appsettings.json:
{
"Lexicala": {
"ApiKey": "your-rapidapi-key-here",
"UseLiteEndpoints": false
}
}
Set UseLiteEndpoints to true if your subscription only allows Lite entry/sense endpoints. When enabled, the client automatically uses:
/search-entries-liteinstead of/search-entries/entries-lite/{entryId}instead of/entries/{entryId}/senses-lite/{senseId}instead of/senses/{senseId}
To restore missing translation details when using lite endpoints, use the translation-enriched methods:
GetEntryWithTranslationsAsync(entryId, targetLanguage)GetSenseWithTranslationsAsync(senseId, targetLanguage)
These methods call translation endpoints to enrich missing sense and example translations.
3. Register Services
In your Program.cs:
using Lexicala.NET;
var builder = WebApplication.CreateBuilder(args);
// Register Lexicala services
builder.Services.RegisterLexicala(builder.Configuration);
var app = builder.Build();
// ... rest of your setup
Supported Frameworks
- .NET 8.0
- .NET 10.0
Getting Started
After configuration, you can inject ILexicalaClient or ILexicalaSearchParser into your services.
Basic Search Example
// Inject ILexicalaClient
public class TranslationService
{
private readonly ILexicalaClient _client;
public TranslationService(ILexicalaClient client)
{
_client = client;
}
public async Task<string> TranslateWordAsync(string word, string fromLang, string toLang)
{
var searchResponse = await _client.BasicSearchAsync(word, fromLang);
if (searchResponse.Results.Any())
{
var entry = await _client.GetEntryAsync(searchResponse.Results.First().Id);
// Translations is Dictionary<string, TranslationObject> keyed by 2-letter language code
var sense = entry.Senses.FirstOrDefault(s => s.Translations.ContainsKey(toLang));
if (sense is not null && sense.Translations.TryGetValue(toLang, out var translationObj))
{
return translationObj.Translation?.Text
?? translationObj.Translations?.FirstOrDefault()?.Text
?? "Translation not found";
}
}
return "Word not found";
}
}
Code Examples
Get Available Languages
var languagesResponse = await lexicalaClient.LanguagesAsync();
var globalLanguages = languagesResponse.Resources.Global;
Console.WriteLine($"Available languages: {string.Join(", ", globalLanguages.SourceLanguages)}");
Basic Search
// Search for "hello" in English
var searchResponse = await lexicalaClient.BasicSearchAsync("hello", "en");
foreach (var result in searchResponse.Results)
{
var headwordText =
result.Headword?.Headword?.Text
?? result.Headword?.HeadwordElementArray?.FirstOrDefault()?.Text
?? "(no headword)";
Console.WriteLine($"Found: {headwordText} (ID: {result.Id})");
}
Advanced Search
var advancedRequest = new AdvancedSearchRequest
{
Language = "en",
SearchText = "run",
Pos = "verb" // Part of speech filter
};
var advancedResponse = await lexicalaClient.AdvancedSearchAsync(advancedRequest);
foreach (var result in advancedResponse.Results)
{
var entry = await lexicalaClient.GetEntryAsync(result.Id);
// Process detailed entry information
}
Using the Search Parser
The ILexicalaSearchParser provides a higher-level abstraction for easier parsing:
// Inject ILexicalaSearchParser
public class SearchService
{
private readonly ILexicalaSearchParser _parser;
public SearchService(ILexicalaSearchParser parser)
{
_parser = parser;
}
public async Task<SearchResultModel> SearchAndParseAsync(string term, string language)
{
return await _parser.SearchAsync(term, language);
}
}
// Usage
var result = await searchService.SearchAndParseAsync("árbol", "es");
var englishSummary = result.Summary("en"); // "tree, shaft, post, mast"
foreach (var searchResult in result.Results)
{
var definition = searchResult.Senses.FirstOrDefault()?.Definition;
Console.WriteLine($"Definition: {definition}");
}
Get Entry Details
var entry = await lexicalaClient.GetEntryAsync("EN00001234"); // Example ID
foreach (var sense in entry.Senses)
{
Console.WriteLine($"Sense: {sense.Definition}");
}
foreach (var headword in entry.Headwords)
{
foreach (var pron in headword.Pronunciations)
{
Console.WriteLine($"Pronunciation: {pron.Value}");
}
}
Testing with Swagger UI
The repository includes an ASP.NET Core minimal Web API demo host with Swagger UI for testing all endpoints.
Clone the repository and navigate to the demo API:
cd source/Demo/Lexicala.NET.Demo.ApiConfigure your Lexicala API key. Choose one of the following:
Recommended: Use User Secrets
dotnet user-secrets init dotnet user-secrets set "Lexicala:ApiKey" "your-rapidapi-key-here"Alternative: Edit appsettings.json
Open
appsettings.jsonin the demo API folder and add:{ "Lexicala": { "ApiKey": "your-rapidapi-key-here", "UseLiteEndpoints": false } }Run the application:
dotnet runOpen Swagger UI in your browser:
- HTTP:
http://localhost:5000/swagger - HTTPS:
https://localhost:5001/swagger
- HTTP:
To use the Sense Sprint web app, see the Sense Sprint documentation for setup and gameplay details.
Available endpoints:
GET /test- Test API connectivityGET /languages- Get available languagesGET /search- Basic searchGET /search-entries- Basic search with full entriesGET /search-entries-lite- Basic search with full entries in lite mode (UseLiteEndpoints=true)GET /search-rdf- Basic search in RDF/JSON-LD formatGET /search-by-definitions- Free-text search in definitionsGET /fluky-search- Random word discoveryGET /entries/{entryId}- Get dictionary entry by IDGET /entries-lite/{entryId}- Get dictionary entry by ID in lite mode (UseLiteEndpoints=true)GET /senses/{senseId}- Get sense by IDGET /senses-lite/{senseId}- Get sense by ID in lite mode (UseLiteEndpoints=true)GET /rdf/{entryId}- Get entry in RDF/JSON-LD formatPOST /search-advanced- Advanced searchPOST /search-entries-advanced- Advanced search with full entriesPOST /search-rdf-advanced- Advanced search in RDF/JSON-LD format
Missing endpoints compared to Rapid Api test console / Lexicala MCP tooling - these endpoints are NOT listed in the official documentation!:
GET /abbreviationsGET /reverse-abbreviationsGET /antonymsGET /definitionsGET /examplesGET /frequenciesGET /phrasesGET /pronunciationsGET /registersGET /semantic-categoriesGET /subcategorizationsGET /synonyms
Implemented in this SDK (not exposed by the demo API host routes):
GET /translate-toGET /translate-exampleGET /translate-phrase
For React frontend development, CORS is enabled for:
http://localhost:3000http://localhost:5173
Demo Game
A dedicated React + Vite frontend for a word guessing game is available at source/Demo/sense-sprint-web.
The web demo currently includes two game modes. Sense Sprint is the lower-cost mode. Translation Quiz makes more Lexicala calls per round because it has to source a word, fetch its entry, and build multiple distractor choices. If you are using a free evaluation subscription, use Translation Quiz sparingly.
Start the backend API (see Testing with Swagger UI above)
In another terminal, navigate to the frontend:
cd source/Demo/sense-sprint-webInstall dependencies and start the dev server:
PowerShell:
npm.cmd install npm.cmd run devBash / Command Prompt:
npm install npm run devOpen the app at
http://localhost:5173
For complete game documentation, features, and tips, see the Sense Sprint README.
Building from Source
Clone the repository:
git clone https://github.com/HannoZ/Lexicala.NET.git cd Lexicala.NETBuild the solution:
dotnet build source/Lexicala.NET.slnxRun tests:
dotnet test source/Lexicala.NET.slnx
The legacy source/Lexicala.NET.sln file has been removed in favor of source/Lexicala.NET.slnx.
Supported API Values
The library validates and supports these commonly used API parameter values:
sourcevalues forFlukySearchAsyncandAdvancedSearch*Async:global,password,random,multigloss- Language parameters (
language,sourceLanguage) must be 2-character language codes AdvancedSearchRequest.Pageaccepts values up to1000AdvancedSearchRequest.Sampleaccepts values up to1000AdvancedSearchRequest.PageLengthaccepts values between1and30(default10)
API Coverage
The library implements the following Lexicala API endpoints:
Utility Endpoints
/test- Test API connectivity/languages- Get available languages
Search Endpoints
/search- Basic search/search-entries- Search with full entries/search-entries-lite- Search with full entries in lite mode (UseLiteEndpoints=true)/search-rdf- Search in RDF/JSON-LD format/search-by-definitions- Free-text search in definitions/fluky-search- Random word discovery
Advanced Search Endpoints
/search-advanced- Advanced search with custom parameters/search-entries-advanced- Advanced search with full entries/search-rdf-advanced- Advanced search in RDF/JSON-LD format
Entry and Sense Endpoints
/entries- Get entry details by ID/entries-lite- Get entry details by ID in lite mode (UseLiteEndpoints=true)/senses- Get sense details by ID/senses-lite- Get sense details by ID in lite mode (UseLiteEndpoints=true)/rdf- Get entry in RDF/JSON-LD format
Translation Endpoints
/translate-to- Translate a lexical unit into a target language/translate-example- Translate an example sentence into a target language/translate-phrase- Translate a phrase into a target language
Lite Translation Enrichment
GetEntryWithTranslationsAsync- Retrieves an entry (including lite mode) and enriches missing sense/example translations using translation endpointsGetSenseWithTranslationsAsync- Retrieves a sense (including lite mode) and enriches missing sense/example translations using translation endpoints
For complete API documentation, visit the Lexicala API Documentation.
Rate Limiting
The Lexicala API enforces a daily request quota. When the quota is exhausted the API returns HTTP 429 Too Many Requests and includes an X-RateLimit-requests-Reset header indicating how many seconds remain until the quota resets.
Retry behaviour
The client uses a Polly-based retry policy with the following rules:
| Condition | Behaviour |
|---|---|
| Transient errors (5xx, network) | Retry up to 3 times with exponential back-off (max 8 s per wait) |
| HTTP 429 — reset ≤ 60 s | Retry up to 3 times, waiting the server-indicated number of seconds between attempts |
| HTTP 429 — reset > 60 s | Fail immediately — no retry; a LexicalaApiException with StatusCode = 429 is thrown |
The 60-second threshold prevents the application from stalling when the quota won't reset for minutes or hours. In that scenario every retry attempt would also receive a 429, so the library surfaces the failure straight away instead of blocking.
Logging
When a request fails due to rate limiting, structured log messages are emitted:
- Warning (before each retry):
Rate limit exceeded (HTTP 429). Waiting {n}s before retry attempt {x}/3. - Warning (skip-retry path):
Rate limit exceeded (HTTP 429). API quota resets in {n}s which exceeds the retry threshold (60s). Not retrying. - Error (after final failure):
API rate limit exceeded (HTTP 429). Quota resets in {n}s. Request failed without retrying because the reset time exceeds the retry threshold.
Handling the exception
try
{
var result = await client.BasicSearchAsync("hello", "en");
}
catch (LexicalaApiException ex) when (ex.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
{
var secondsUntilReset = ex.Metadata?.RateLimits?.Reset;
Console.WriteLine($"Daily quota exceeded. Quota resets in {secondsUntilReset}s.");
}
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Caching.Memory (>= 10.0.7)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
- Microsoft.Extensions.Http.Polly (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Lexicala.NET:
| Package | Downloads |
|---|---|
|
Lexicala.NET.MicrosoftDependencyInjection
IoC container registration that uses the Microsoft.DependencyInjection.IServiceCollection for .NET Core applications. |
|
|
Lexicala.NET.Autofac
Autofac IoC container registration for Lexicala.NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.0-beta.2 | 52 | 5/17/2026 |
| 3.1.0 | 95 | 5/12/2026 |
| 3.0.0 | 120 | 4/29/2026 |
| 2.0.0 | 384 | 4/8/2024 |
| 1.7.0 | 1,497 | 11/18/2022 |
| 1.6.1 | 1,813 | 3/11/2022 |
| 1.6.0.1 | 1,015 | 12/9/2021 |
| 1.5.0 | 1,102 | 7/25/2021 |
| 1.4.0 | 1,198 | 7/24/2021 |
| 1.3.0 | 1,491 | 11/23/2020 |
| 1.2.0 | 1,378 | 10/15/2020 |
| 1.1.1 | 1,209 | 10/12/2020 |
| 1.1.0 | 1,586 | 10/11/2020 |
| 1.0.0 | 1,478 | 10/8/2020 |
A .NET client for the Lexicala api.
See readme file on project page for further details.