Sawalni Python SDK
This is the official Python SDK for the Sawalni API, providing easy access to language-related services such as embedding generation, language identification, and translation. Sawalni API is developed by Omneity Labs, and provides unique multilingual models and NLP capabilities, including pioneering Moroccan Darija support.
Installation
Install the package using pip:
pip install sawalni
Quick Start
To use the Sawalni SDK, you'll need an API key. You can set it as an environment variable or pass it directly to the client:
from sawalni import Sawalni
client = Sawalni(api_key='your_api_key_here')
# or specify the key via SAWALNI_API_KEY in the environment
Features
The SDK supports both synchronous and asynchronous operations for the following services:
- Chat: Generate chat completions using our
Sawalnimultilingual models, supporting Moroccan Darija, English, French, Arabic and many other languages. - Search: Perform internet searches in multiple languages with a single query.
- Generate Embeddings: Create embeddings for text in multiple languages using
Madmon. - Identify Language: Detect the language of a given text with
Gherbal, supporting up to 33 languages. - Translate Text: Translate text between 13 supported languages with
Tarjamli. - Transliterate Text: Convert Moroccan Arabic script to Moroccan Latin script with
Daktilo.
The Sawalni SDK includes an OpenAI compatible client, which can be accessed via the chat and embeddings properties, or direct use via the OpenAI client as detailed below.
Chat
# Available models: sawalni-micro, sawalni-mini, sawalni-small
chat = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-small")
# Stream
stream = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-small", stream=True)
for chunk in stream:
print(chunk.choices[0].delta.content)
Search
search = client.search("Hello, how are you?")
Generate Embeddings
embeddings = client.embed("Hello, world!")
Identify Language
language = client.identify("Bonjour le monde")
Translate Text
# You can specify a source language or let the model detect it automatically
translation = client.translate("Hello", source="auto", target="ary_Latn")
Transliterate Text
transliteration = client.transliterate("اهلا بيك", model="daktilo-mini", to="latn", temperature=0.1)
# {"text": "ahlane bik"}
Asynchronous Usage
For asynchronous operations, use the SawalniAsync client:
from sawalni import SawalniAsync
async_client = SawalniAsync(api_key='your_api_key_here')
embeddings = await async_client.embed("Hello, world!")
OpenAI compatible client
The SDK also includes an OpenAI compatible client, which can be accessed via the chat and embeddings properties:
chat = client.chat
embeddings = client.embeddings
You can also use the OpenAI client directly with the base URL set to https://api.sawalni.com/v1 and the API key set to your Sawalni API key.
import openai
client = openai.OpenAI(base_url="https://api.sawalni.com/v1", api_key="your_api_key_here")
Only the chat and embeddings properties are supported with this approach.
Documentation
For detailed information about available models, parameters, languages and and response formats, please refer to the complete API documentation at https://api.sawalni.com.
Support
If you encounter any issues or have questions, please contact api@sawalni.com.
Metadata
Release files for sawalni 0.2.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sawalni-0.2.11.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sawalni-0.2.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.9 kB
Release files / sawalni-0.2.11.tar.gz
| Download URL | sawalni-0.2.11.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87daca6df15ac35475245029a79a9d466f823efcce42312f630a29291ef6383f
|
|
BLAKE2b-256 checksum How to use checksums |
65d4128478eb83e9bbc045ed7456b8147948beddfa403adf08de3d01f3572332
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.10
|
Release files / sawalni-0.2.11-py3-none-any.whl
| Download URL | sawalni-0.2.11-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9703376f6d3eb15fdb5c6823b249c8d7a0532e67408ec423e341c7e65fe9290c
|
|
BLAKE2b-256 checksum How to use checksums |
bd8d6c10f20ffe856ab1a20517b5b823f7421d66ea8652c3a409977ffcc6ba78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.10
|