Skip to main content

Official Python SDK for the Sawalni API

Project description

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:

  1. Chat (OpenAI compatible)
  2. Search (search the internet for information)
  3. Generate Embeddings (languages depend on the model)
  4. Identify Language (35 languages supported)
  5. Translate Text (13 languages supported)

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-zero, sawalni-micro, sawalni-mini
chat = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-zero")

# Stream
stream = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-zero", 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

translation = client.translate("Hello", source="eng_Latn", target="ary_Latn")

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.

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

sawalni-0.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

sawalni-0.2.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file sawalni-0.2.0.tar.gz.

File metadata

  • Download URL: sawalni-0.2.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for sawalni-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2aee23744fb689d3c0c1ef0ebb282911d9ece435b573b00741e7173a4f477d02
MD5 bff502dfb31341421b713fc60cdc5271
BLAKE2b-256 881cb2144342825f132a5bccfdb8c1f223fa0ea7b2eafdf24408dbc55e01228d

See more details on using hashes here.

File details

Details for the file sawalni-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sawalni-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for sawalni-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e46dbd145a22c3f191e9f7eff8aefbbe7f49a160a554025db1c78dfa33cf607
MD5 698de3c63d012b35aa47b9171de20527
BLAKE2b-256 c6652e202a6fa01ecbc1c16afb7bcbd9d955b1d877bd87555aaa7755af2ae836

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