Unofficial Claude2 API supporting direct HTTP chat creation/deletion/retrieval, message attachments and auto session gathering using Firefox with geckodriver.
Project description
unofficial-claude2-api
Claude2 unofficial API supporting direct HTTP chat creation/deletion/retrieval, message attachments and auto session gathering using Firefox with geckodriver.
How to install
pip install unofficial-claude2-api
Uninstallation
pip uninstall unofficial-claude2-api
Requirements
These requirements are needed to auto retrieve session cookie and UserAgent using selenium
-
Firefox installed, and with at least one profile logged into Claude.
-
geckodriver installed inside a folder registered in PATH environment variable.
Example Usage
from claude2_api.client import (
ClaudeAPIClient,
get_session_data,
MessageRateLimitHit,
)
FILEPATH = "test.txt"
# This function will automatically retrieve a SessionData instance using selenium
# Omitting profile argument will use default Firefox profile
data = get_session_data()
# Initialize a client instance using a session
client = ClaudeAPIClient(data)
# Create a new chat and cache the chat_id
chat_id = client.create_chat()
try:
# Used for sending message with or without attachment
answer = client.send_message(
chat_id, "Hello!", attachment_path=FILEPATH, timeout=240
)
# May return None, in that case, delay a bit and retry
print(answer)
except MessageRateLimitHit as e:
# The exception will hold these informations about the rate limit:
print(f"\nMessage limit hit, resets at {e.resetDate}")
print(f"\n{e.sleep_sec} seconds left until -> {e.resetTimestamp}")
quit()
finally:
# Perform chat deletion for cleanup
client.delete_chat(chat_id)
# Get a list of all chats ids
all_chat_ids = client.get_all_chat_ids()
# Delete all chats
for chat in all_chat_ids:
client.delete_chat(chat)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for unofficial-claude2-api-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6121fcdb9eaa9ae85094cc67df67c60df94d556339297140ca90751d3b634223 |
|
MD5 | 9f017c05c5930088cd730c8204fee32b |
|
BLAKE2b-256 | 2143b14e4bb95e0dafbf1f70fbadafb8b7d40c10ccc4ddfa866518663d0f63a4 |
Close
Hashes for unofficial_claude2_api-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34276ffbed75e553357f988e66048aa1ce2eb197945181b0e59b628830d1fbfd |
|
MD5 | 2572d7dd0c716c0190552826f858b56c |
|
BLAKE2b-256 | a1601ad5a2eaad866d72dbc198d3a27138c8aaaefe3310fc1fd248bf670c5fb5 |