Skip to main content

pyChatGPT

PyPi License PyPi

An unofficial Python wrapper for OpenAI's ChatGPT API

Features

  • Bypass Cloudflare's anti-bot protection using undetected_chromedriver
  • Captcha solver when auth with login credentials (experimental)
  • Support headless machines
  • Proxy support (only without basic auth)

Getting Started

On version 0.3.0, this library is using only the undetected_chromedriver to bypass Cloudflare's anti-bot protection. requests module is no longer used due to the complexity of the protection. Please make sure you have Google Chrome before using this wrapper. From now on, this library will not support specifying a conversation (i.e. parent_id and conversation_id parameters) but you can still reset the conversation by calling reset_conversation().

Installation

pip install -U pyChatGPT

Usage

Obtaining session_token

  1. Go to https://chat.openai.com/chat and open the developer tools by F12.
  2. Find the __Secure-next-auth.session-token cookie in Application > Storage > Cookies > https://chat.openai.com.
  3. Copy the value in the Cookie Value field.

image

Interactive mode

python -m pyChatGPT

Import as a module

from pyChatGPT import ChatGPT

session_token = 'abc123'  # `__Secure-next-auth.session-token` cookie from https://chat.openai.com/chat
api = ChatGPT(session_token)  # auth with session token
api2 = ChatGPT(email='example@domain.com', password='password')  # auth with email and password (unreliable)
api3 = ChatGPT(session_token, conversation_id='some-random-uuid', parent_id='another-random-uuid')  # specify a conversation
api4 = ChatGPT(session_token, proxy='http://proxy.example.com:8080')  # specify proxy
api5 = ChatGPT(session_token, cf_refresh_interval=30)  # specify the interval to refresh the cf cookies (in minutes)

resp = api.send_message('Hello, world!')
print(resp['message'])

api.reset_conversation()  # reset the conversation

Frequently Asked Questions

How do I get it to work on headless linux server?

# install chromium & X virtual framebuffer
sudo apt install chromium xvfb

# start your script
python3 your_script.py

Insipration

This project is inspired by

Disclaimer

This project is not affiliated with OpenAI in any way. Use at your own risk. I am not responsible for any damage caused by this project. Please read the OpenAI Terms of Service before using this project.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details.

Metadata

Release files for pyChatGPT 0.3.0

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

Source distribution (sdist)

Source distribution for pyChatGPT 0.3.0
File Size Uploaded
pyChatGPT-0.3.0.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyChatGPT 0.3.0
File Interpreter ABI Platform
pyChatGPT-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.8 kB

Release files / pyChatGPT-0.3.0.tar.gz

Download URL pyChatGPT-0.3.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f9635562443ce2722082ee0936bcac3bd22e978c6532f4c07e7547526c8d2a18
BLAKE2b-256 checksum
How to use checksums
b2c3ea9d3040fa3a01418c2584af5b022ec54985f2e5ddfefb19d57ff397c4b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / pyChatGPT-0.3.0-py3-none-any.whl

Download URL pyChatGPT-0.3.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
704c6e8e5b84077da60713d09c9d9a531ffeb7cd239f9940bf0e79e76cb66022
BLAKE2b-256 checksum
How to use checksums
c73b4502ac7fc9d07934ab592a6243ad1a96c42f24eadc2b41fa35687d75cd7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release history Release notifications | RSS feed

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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