The official Python library for the Chat Nio API
Project description
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
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")
# clear token
chatnio.clear_key()
# get current token
chatnio.get_token()
Chat
chat = await chatnio.new_chat()
chat.send_message("Hello World", "user_id")
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 month
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
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
chatnio-0.1.2.tar.gz
(15.2 kB
view hashes)
Built Distribution
Close
Hashes for chatnio-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5ea07a2834062b5a56d180da04dd457ad18c5715482a3972708e813bd90d170 |
|
MD5 | faad3e21e5a1aaf8fd4ce8ccfc788d41 |
|
BLAKE2b-256 | 8abfc64793986c6354a7ab18e8e481b2bed58a49d4931a60ad7bf46368378c19 |