chatnio


Namechatnio JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/Deeptrain-Community/chatnio-api-python
SummaryThe official Python library for the Chat Nio API
upload_time2023-12-29 11:21:27
maintainer
docs_urlNone
authorDeeptrain Community
requires_python>=3.6
licenseMIT license
keywords chatnio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ======================
ChatNio Python Library
======================


The official Python library for the Chat Nio API

* Authors: Deeptrain Team
* Free software: MIT license
* Documentation: https://docs.chatnio.net

Features
========

* Chat
* Conversation
* Quota
* Subscription and Package


Installation
============

Install using `pip`

.. code-block:: bash

    pip install --upgrade chatnio

And then import it

.. code-block:: python

    import chatnio


Usage
=====

* Authentication

.. code-block:: python

    chatnio.set_key("sk-...")
    # or read from environment variable
    chatnio.set_key_from_env("CHATNIO_TOKEN")

    # set custom api endpoint (default: https://api.chatnio.net)
    # chatnio.set_endpoint("https://example.com/api")

    # clear token
    chatnio.clear_key()

    # get current token
    chatnio.get_token()


* Chat

.. code-block:: python

    chat = await chatnio.new_chat()

    async for message in chat.ask("Hello, world!"):
        print(message.message, end="")


* Conversation

.. code-block:: python

    # list conversations (100 conversations max)
    for conversation in chatnio.list_conversations():
        print(conversation.id, conversation.name)

    # load conversation
    conversation = chatnio.load_conversation(42)
    print(conversation)
    for message in conversation.messages:
        print(message.role, message.content)

    # delete conversation
    state = chatnio.delete_conversation(42)
    print(state)


* Quota

.. code-block:: python

    # get quota
    quota = chatnio.get_quota()
    print(quota)

    # buy quota
    state = chatnio.buy_quota(1000)
    print(state)


* Subscription and Package

.. code-block:: python

    # get subscription
    subscription = chatnio.get_subscription()
    print(subscription.is_subscribed, subscription.expired)

    # buy subscription
    state = chatnio.buy_subscription(1, 1) # 1 month of basic plan
    print(state)

    # get package
    package = chatnio.get_package()
    print(package)


* Error

    chatnio.AuthenticationError


Test
====

To run the tests, you need to set the environment variable `CHATNIO_TOKEN` to your secret key.

.. code-block:: bash

    export CHATNIO_TOKEN="sk-..."

Then run the tests

.. code-block:: bash

    pytest



=======
History
=======

- 0.1.0 (2023-10-13)
    * First release on PyPI.
- 0.1.1 (2023-10-14)
    * Update Documentation
- 0.1.2 (2023-10-31)
    * Update API
- 0.1.3 (2023-11-29)
    * Add Subscription Level
- 0.1.4 (2023-12-01)
    * Add Customize Endpoint Option

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Deeptrain-Community/chatnio-api-python",
    "name": "chatnio",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "chatnio",
    "author": "Deeptrain Community",
    "author_email": "zmh@lightxi.com",
    "download_url": "https://files.pythonhosted.org/packages/89/85/7ac79d7e37c109fcc299f84a3b8b1fb2d0680abe624033d29c1a1d87a301/chatnio-0.1.4.tar.gz",
    "platform": null,
    "description": "======================\nChatNio Python Library\n======================\n\n\nThe official Python library for the Chat Nio API\n\n* Authors: Deeptrain Team\n* Free software: MIT license\n* Documentation: https://docs.chatnio.net\n\nFeatures\n========\n\n* Chat\n* Conversation\n* Quota\n* Subscription and Package\n\n\nInstallation\n============\n\nInstall using `pip`\n\n.. code-block:: bash\n\n    pip install --upgrade chatnio\n\nAnd then import it\n\n.. code-block:: python\n\n    import chatnio\n\n\nUsage\n=====\n\n* Authentication\n\n.. code-block:: python\n\n    chatnio.set_key(\"sk-...\")\n    # or read from environment variable\n    chatnio.set_key_from_env(\"CHATNIO_TOKEN\")\n\n    # set custom api endpoint (default: https://api.chatnio.net)\n    # chatnio.set_endpoint(\"https://example.com/api\")\n\n    # clear token\n    chatnio.clear_key()\n\n    # get current token\n    chatnio.get_token()\n\n\n* Chat\n\n.. code-block:: python\n\n    chat = await chatnio.new_chat()\n\n    async for message in chat.ask(\"Hello, world!\"):\n        print(message.message, end=\"\")\n\n\n* Conversation\n\n.. code-block:: python\n\n    # list conversations (100 conversations max)\n    for conversation in chatnio.list_conversations():\n        print(conversation.id, conversation.name)\n\n    # load conversation\n    conversation = chatnio.load_conversation(42)\n    print(conversation)\n    for message in conversation.messages:\n        print(message.role, message.content)\n\n    # delete conversation\n    state = chatnio.delete_conversation(42)\n    print(state)\n\n\n* Quota\n\n.. code-block:: python\n\n    # get quota\n    quota = chatnio.get_quota()\n    print(quota)\n\n    # buy quota\n    state = chatnio.buy_quota(1000)\n    print(state)\n\n\n* Subscription and Package\n\n.. code-block:: python\n\n    # get subscription\n    subscription = chatnio.get_subscription()\n    print(subscription.is_subscribed, subscription.expired)\n\n    # buy subscription\n    state = chatnio.buy_subscription(1, 1) # 1 month of basic plan\n    print(state)\n\n    # get package\n    package = chatnio.get_package()\n    print(package)\n\n\n* Error\n\n    chatnio.AuthenticationError\n\n\nTest\n====\n\nTo run the tests, you need to set the environment variable `CHATNIO_TOKEN` to your secret key.\n\n.. code-block:: bash\n\n    export CHATNIO_TOKEN=\"sk-...\"\n\nThen run the tests\n\n.. code-block:: bash\n\n    pytest\n\n\n\n=======\nHistory\n=======\n\n- 0.1.0 (2023-10-13)\n    * First release on PyPI.\n- 0.1.1 (2023-10-14)\n    * Update Documentation\n- 0.1.2 (2023-10-31)\n    * Update API\n- 0.1.3 (2023-11-29)\n    * Add Subscription Level\n- 0.1.4 (2023-12-01)\n    * Add Customize Endpoint Option\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "The official Python library for the Chat Nio API",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/Deeptrain-Community/chatnio-api-python"
    },
    "split_keywords": [
        "chatnio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed82e192e0b1c05e4ae622ac43face29c40a6fe83e90e913a5782eaa356af2f8",
                "md5": "82a0f0ab8133ed5d09495423c4f81af1",
                "sha256": "1f6e0fe81a0c4d30f6b1eba3e899f60c94163b826bbfb29c68a17c42f1fa59b3"
            },
            "downloads": -1,
            "filename": "chatnio-0.1.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "82a0f0ab8133ed5d09495423c4f81af1",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 9545,
            "upload_time": "2023-12-29T11:21:22",
            "upload_time_iso_8601": "2023-12-29T11:21:22.501031Z",
            "url": "https://files.pythonhosted.org/packages/ed/82/e192e0b1c05e4ae622ac43face29c40a6fe83e90e913a5782eaa356af2f8/chatnio-0.1.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "89857ac79d7e37c109fcc299f84a3b8b1fb2d0680abe624033d29c1a1d87a301",
                "md5": "f56bfaa86011222a8a69e09092c72860",
                "sha256": "08b83a60a6b422a2a0d8b66484f333fe36aa3006c27ea66e0de09d6e3c9d6d9f"
            },
            "downloads": -1,
            "filename": "chatnio-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "f56bfaa86011222a8a69e09092c72860",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 15352,
            "upload_time": "2023-12-29T11:21:27",
            "upload_time_iso_8601": "2023-12-29T11:21:27.294556Z",
            "url": "https://files.pythonhosted.org/packages/89/85/7ac79d7e37c109fcc299f84a3b8b1fb2d0680abe624033d29c1a1d87a301/chatnio-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-29 11:21:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Deeptrain-Community",
    "github_project": "chatnio-api-python",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "chatnio"
}
        
Elapsed time: 0.15920s