Skip to main content

ChatNio Python Library

The official Python library for the Chat Nio API

Features

  • Chat

  • Conversation

  • Quota

  • Subscription and Package

Installation

Install using pip

pip install --upgrade chatnio

And then import it

import chatnio

Usage

  • Authentication

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

chat = await chatnio.new_chat()

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

# 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

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

# buy quota
state = chatnio.buy_quota(1000)
print(state)
  • Subscription and Package

# 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.

export CHATNIO_TOKEN="sk-..."

Then run the tests

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

Metadata

Release files for chatnio 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatnio 0.1.4
File Size Uploaded Provenance
chatnio-0.1.4.tar.gz 15.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for chatnio 0.1.4
File Interpreter ABI Platform
chatnio-0.1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 24.9 kB

Release files / chatnio-0.1.4.tar.gz

Download URL chatnio-0.1.4.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
08b83a60a6b422a2a0d8b66484f333fe36aa3006c27ea66e0de09d6e3c9d6d9f
BLAKE2b-256 checksum
How to use checksums
89857ac79d7e37c109fcc299f84a3b8b1fb2d0680abe624033d29c1a1d87a301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / chatnio-0.1.4-py2.py3-none-any.whl

Download URL chatnio-0.1.4-py2.py3-none-any.whl
Size 9.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1f6e0fe81a0c4d30f6b1eba3e899f60c94163b826bbfb29c68a17c42f1fa59b3
BLAKE2b-256 checksum
How to use checksums
ed82e192e0b1c05e4ae622ac43face29c40a6fe83e90e913a5782eaa356af2f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Security for chatnio 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page