sawalni


Namesawalni JSON
Version 0.2.11 PyPI version JSON
download
home_pageNone
SummaryOfficial Python SDK for the Sawalni API
upload_time2025-01-04 00:43:07
maintainerNone
docs_urlNone
authorOmar Kamali
requires_python>=3.7
licenseNone
keywords nlp language processing embedding translation transliteration identification api sdk moroccan darija arabic multilingual low-resource languages
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://sawalni.com/developers), and provides unique multilingual models and NLP capabilities, including pioneering Moroccan Darija support.

## Installation

Install the package using pip:

```bash
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:

```py
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**: Generate chat completions using our `Sawalni` multilingual models, supporting Moroccan Darija, English, French, Arabic and many other languages.
2. **Search**: Perform internet searches in multiple languages with a single query.
3. **Generate Embeddings**: Create embeddings for text in multiple languages using `Madmon`.
4. **Identify Language**: Detect the language of a given text with `Gherbal`, supporting up to 33 languages.
5. **Translate Text**: Translate text between 13 supported languages with `Tarjamli`.
6. **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

```py
# 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

```py
search = client.search("Hello, how are you?")
```

### Generate Embeddings

```py
embeddings = client.embed("Hello, world!")
```

### Identify Language

```py
language = client.identify("Bonjour le monde")
```

### Translate Text

```py
# You can specify a source language or let the model detect it automatically
translation = client.translate("Hello", source="auto", target="ary_Latn")
```

### Transliterate Text

```py
transliteration = client.transliterate("اهلا بيك", model="daktilo-mini", to="latn", temperature=0.1)

# {"text": "ahlane bik"}
```

## Asynchronous Usage

For asynchronous operations, use the SawalniAsync client:

```py
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:

```py
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.

```py
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sawalni",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "nlp language processing embedding translation transliteration identification api sdk moroccan darija arabic multilingual low-resource languages",
    "author": "Omar Kamali",
    "author_email": "api@sawalni.com",
    "download_url": "https://files.pythonhosted.org/packages/65/d4/128478eb83e9bbc045ed7456b8147948beddfa403adf08de3d01f3572332/sawalni-0.2.11.tar.gz",
    "platform": null,
    "description": "# Sawalni Python SDK\n\nThis 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](https://sawalni.com/developers), and provides unique multilingual models and NLP capabilities, including pioneering Moroccan Darija support.\n\n## Installation\n\nInstall the package using pip:\n\n```bash\npip install sawalni\n```\n\n## Quick Start\n\nTo 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:\n\n```py\nfrom sawalni import Sawalni\n\nclient = Sawalni(api_key='your_api_key_here') \n# or specify the key via SAWALNI_API_KEY in the environment\n```\n\n## Features\n\nThe SDK supports both synchronous and asynchronous operations for the following services:\n\n1. **Chat**: Generate chat completions using our `Sawalni` multilingual models, supporting Moroccan Darija, English, French, Arabic and many other languages.\n2. **Search**: Perform internet searches in multiple languages with a single query.\n3. **Generate Embeddings**: Create embeddings for text in multiple languages using `Madmon`.\n4. **Identify Language**: Detect the language of a given text with `Gherbal`, supporting up to 33 languages.\n5. **Translate Text**: Translate text between 13 supported languages with `Tarjamli`.\n6. **Transliterate Text**: Convert Moroccan Arabic script to Moroccan Latin script with `Daktilo`.\n\nThe 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.\n\n### Chat\n\n```py\n# Available models: sawalni-micro, sawalni-mini, sawalni-small\nchat = client.chat.completions.create(messages=[{\"role\": \"user\", \"content\": \"Hello, how are you?\"}], model=\"sawalni-small\")\n\n# Stream\nstream = client.chat.completions.create(messages=[{\"role\": \"user\", \"content\": \"Hello, how are you?\"}], model=\"sawalni-small\", stream=True)\nfor chunk in stream:\n    print(chunk.choices[0].delta.content)\n```\n\n### Search\n\n```py\nsearch = client.search(\"Hello, how are you?\")\n```\n\n### Generate Embeddings\n\n```py\nembeddings = client.embed(\"Hello, world!\")\n```\n\n### Identify Language\n\n```py\nlanguage = client.identify(\"Bonjour le monde\")\n```\n\n### Translate Text\n\n```py\n# You can specify a source language or let the model detect it automatically\ntranslation = client.translate(\"Hello\", source=\"auto\", target=\"ary_Latn\")\n```\n\n### Transliterate Text\n\n```py\ntransliteration = client.transliterate(\"\u0627\u0647\u0644\u0627 \u0628\u064a\u0643\", model=\"daktilo-mini\", to=\"latn\", temperature=0.1)\n\n# {\"text\": \"ahlane bik\"}\n```\n\n## Asynchronous Usage\n\nFor asynchronous operations, use the SawalniAsync client:\n\n```py\nfrom sawalni import SawalniAsync\n\nasync_client = SawalniAsync(api_key='your_api_key_here')\nembeddings = await async_client.embed(\"Hello, world!\")\n```\n\n## OpenAI compatible client\n\nThe SDK also includes an OpenAI compatible client, which can be accessed via the `chat` and `embeddings` properties:\n\n```py\nchat = client.chat\nembeddings = client.embeddings\n```\n\nYou 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.\n\n```py\nimport openai\nclient = openai.OpenAI(base_url=\"https://api.sawalni.com/v1\", api_key=\"your_api_key_here\")\n```\n\nOnly the `chat` and `embeddings` properties are supported with this approach.\n\n## Documentation\n\nFor detailed information about available models, parameters, languages and and response formats, please refer to the complete API documentation at https://api.sawalni.com.\n\n## Support\n\nIf you encounter any issues or have questions, please contact api@sawalni.com.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Official Python SDK for the Sawalni API",
    "version": "0.2.11",
    "project_urls": null,
    "split_keywords": [
        "nlp",
        "language",
        "processing",
        "embedding",
        "translation",
        "transliteration",
        "identification",
        "api",
        "sdk",
        "moroccan",
        "darija",
        "arabic",
        "multilingual",
        "low-resource",
        "languages"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd8d6c10f20ffe856ab1a20517b5b823f7421d66ea8652c3a409977ffcc6ba78",
                "md5": "6ea6a02897c6913267d4de0a647051d5",
                "sha256": "9703376f6d3eb15fdb5c6823b249c8d7a0532e67408ec423e341c7e65fe9290c"
            },
            "downloads": -1,
            "filename": "sawalni-0.2.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6ea6a02897c6913267d4de0a647051d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5860,
            "upload_time": "2025-01-04T00:43:06",
            "upload_time_iso_8601": "2025-01-04T00:43:06.803586Z",
            "url": "https://files.pythonhosted.org/packages/bd/8d/6c10f20ffe856ab1a20517b5b823f7421d66ea8652c3a409977ffcc6ba78/sawalni-0.2.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "65d4128478eb83e9bbc045ed7456b8147948beddfa403adf08de3d01f3572332",
                "md5": "2cc008d3c5e12c41a07f9d14ce03ae69",
                "sha256": "87daca6df15ac35475245029a79a9d466f823efcce42312f630a29291ef6383f"
            },
            "downloads": -1,
            "filename": "sawalni-0.2.11.tar.gz",
            "has_sig": false,
            "md5_digest": "2cc008d3c5e12c41a07f9d14ce03ae69",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6057,
            "upload_time": "2025-01-04T00:43:07",
            "upload_time_iso_8601": "2025-01-04T00:43:07.834171Z",
            "url": "https://files.pythonhosted.org/packages/65/d4/128478eb83e9bbc045ed7456b8147948beddfa403adf08de3d01f3572332/sawalni-0.2.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-04 00:43:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sawalni"
}
        
Elapsed time: 0.42788s