sawalni


Namesawalni JSON
Version 0.2.3 PyPI version JSON
download
home_pageNone
SummaryOfficial Python SDK for the Sawalni API
upload_time2024-11-16 22:26:03
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/d4/db/e8d80f3f1cbaea1a2a082f6e0c3fba270cba9f6335a470af2ca8944ec551/sawalni-0.2.3.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.3",
    "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": "758840ff3b1743fedd4dd5f776d9ed25768d3da62341a49a0892c94dfd1a605d",
                "md5": "cff2327126d11a1bbcb3f5cf7981e0c4",
                "sha256": "b6a2731056772ca0bf78cc037c59ecb9915218e59f32c96b11c84dbdb170e0db"
            },
            "downloads": -1,
            "filename": "sawalni-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cff2327126d11a1bbcb3f5cf7981e0c4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5702,
            "upload_time": "2024-11-16T22:25:59",
            "upload_time_iso_8601": "2024-11-16T22:25:59.987561Z",
            "url": "https://files.pythonhosted.org/packages/75/88/40ff3b1743fedd4dd5f776d9ed25768d3da62341a49a0892c94dfd1a605d/sawalni-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d4dbe8d80f3f1cbaea1a2a082f6e0c3fba270cba9f6335a470af2ca8944ec551",
                "md5": "49264a5f47a08f4dbae9c6a064f8c297",
                "sha256": "8f16929f977b21f4ae7da2c372c18169171ca30f8ed3e625443bb81e45599081"
            },
            "downloads": -1,
            "filename": "sawalni-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "49264a5f47a08f4dbae9c6a064f8c297",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5929,
            "upload_time": "2024-11-16T22:26:03",
            "upload_time_iso_8601": "2024-11-16T22:26:03.563447Z",
            "url": "https://files.pythonhosted.org/packages/d4/db/e8d80f3f1cbaea1a2a082f6e0c3fba270cba9f6335a470af2ca8944ec551/sawalni-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-16 22:26:03",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sawalni"
}
        
Elapsed time: 1.58711s