Skip to main content

An unofficial asynchronous api wrapper for Character AI

Project description

PyCharacterAI

An unofficial asynchronous api wrapper for Character AI. For Python.

This library is based on the Character AI Unofficial Node API, made by realcoloride.

If you have any questions or problems, please contact me on Discord (xtraf) or Telegram.

Installation

pip install PyCharacterAI

Getting started

First, import and create a new instance of the Client class

from PyCharacterAI import Client
client = Client()

This library allows you to log in in two ways.

  1. As a guest (Some api features are not available):
await client.authenticate_as_guest()
  1. Using a token.
token = 'TOKEN'
await client.authenticate_with_token(token)

Instructions for getting a token:

  1. Open the Character AI website in your browser
  2. Open the developer tools F12 and go to the Application tab.
  3. Go to the Storage section and click on Local Storage.
  4. Look for the @@auth0spajs@@::dyD3gE281MqgISG7FuIXYhL2WEknqZzv::https://auth0.character.ai/::openid profile email offline_access key.
  5. Open the body and copy the access token.

Access_Token

вљ пёЏ Warning! Do not share this token with anyone!

Simple example

import asyncio
from PyCharacterAI import Client

token = "TOKEN"


async def main():
    client = Client()
    await client.authenticate_with_token(token)

    username = (await client.fetch_user())['user']['user']['username']
    print(f'Authenticated as {username}')

    character_id = "iV5qb8ttzD7Ytl69U_-ONcW2tW_lrFrOVKExyKJHlJM"  # Lily (by @landon)
    chat = await client.create_or_continue_chat(character_id)

    while True:
        message = input(f'{username}: ')  # In: Hi!

        answer = await chat.send_message(message)
        print(f"Character: {answer.text}")  # Out: hello there! what kind of question you gonna ask me ? i'm here to assist you :)


asyncio.run(main())

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

PyCharacterAI-1.0.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyCharacterAI-1.0.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file PyCharacterAI-1.0.0.tar.gz.

File metadata

  • Download URL: PyCharacterAI-1.0.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for PyCharacterAI-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a413b86c4c230d2dedcfe3943a59b457ae9bee414fb570cde8b11eab2701d6f6
MD5 4c829180b56bcaf40967a4dc4aba9448
BLAKE2b-256 a0e821729a5b91db6c507f18b40bbd7967d4bb7fa6a4c3b3d31fd76f1cdf6f42

See more details on using hashes here.

File details

Details for the file PyCharacterAI-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: PyCharacterAI-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for PyCharacterAI-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d41df28f170d9d227322345f5027327da86790e5893c246f0bea537d56d2d585
MD5 34463b92f89fd50b0ba2996e071af8e7
BLAKE2b-256 e0904ce9cf734892b305ffde8c54afcaa14ef61c545828bc2209e8c6aa6ca790

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page