{"id":13643740,"url":"https://github.com/rawandahmad698/pychatgpt","last_synced_at":"2025-04-10T23:26:19.262Z","repository":{"id":64252311,"uuid":"574428530","full_name":"rawandahmad698/PyChatGPT","owner":"rawandahmad698","description":"⚡️ Python client for the unofficial ChatGPT API with auto token regeneration, conversation tracking, proxy support and more.","archived":false,"fork":false,"pushed_at":"2023-01-05T19:45:36.000Z","size":104,"stargazers_count":4217,"open_issues_count":41,"forks_count":440,"subscribers_count":97,"default_branch":"master","last_synced_at":"2025-04-03T17:52:55.358Z","etag":null,"topics":["chatgpt","openai","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rawandahmad698.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-05T09:41:51.000Z","updated_at":"2025-04-02T14:06:02.000Z","dependencies_parsed_at":"2023-01-15T06:45:39.896Z","dependency_job_id":null,"html_url":"https://github.com/rawandahmad698/PyChatGPT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rawandahmad698%2FPyChatGPT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rawandahmad698%2FPyChatGPT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rawandahmad698%2FPyChatGPT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rawandahmad698%2FPyChatGPT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rawandahmad698","download_url":"https://codeload.github.com/rawandahmad698/PyChatGPT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313842,"owners_count":21082928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","openai","python"],"created_at":"2024-08-02T01:01:51.981Z","updated_at":"2025-04-10T23:26:19.230Z","avatar_url":"https://github.com/rawandahmad698.png","language":"Python","funding_links":["https://www.buymeacoffee.com/rawandahmed"],"categories":["CLIs"],"sub_categories":[],"readme":"[Discord Discussion](https://discord.gg/MqeaZsy4F5)\nCurrent State: Not maintained. Not Working.\n\nSorry guys! Really busy with private projects. This was very fun!\n\n\n# 🔥 PyChatGPT\n[Read More - How OpenAI filters requests made by bots/scrapers](https://github.com/rawandahmad698/PyChatGPT/discussions/103)\n\n[![Python](https://img.shields.io/badge/python-3.8-blue.svg)](https://img.shields.io/badge/python-3.8-blue.svg)\n[![PyPi](https://img.shields.io/pypi/v/chatgptpy.svg)](https://pypi.python.org/pypi/chatgptpy)\n[![PyPi](https://img.shields.io/pypi/dm/chatgptpy.svg)](https://pypi.python.org/pypi/chatgptpy)\n\n*⭐️ Like this repo? please star \u0026 consider donating to keep it maintained*\n\n\u003ca href=\"https://www.buymeacoffee.com/rawandahmed\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\n*💡 If OpenAI change their API, I will fix it as soon as possible, so \u003cmark\u003eWatch\u003c/mark\u003e the repo if you want to be notified*\n\n### Features\n- [x] Save Conversations to a file\n- [x] Resume conversations even after closing the program\n- [x] Proxy Support\n- [x] Automatically login without involving a browser\n- [x] Automatically grab Access Token\n- [x] Get around the login **captcha** (If you try to log in subsequently, you will be prompted to solve a captcha)\n- [x] Saves the access token to a file, so you don't have to log in again\n- [x] Automatically refreshes the access token when it expires\n- [x] Uses colorama to colorize the output, because why not?\n- [x] Smart Conversation Tracking \n\n## Web Demo\nIntegrated into [Huggingface Spaces 🤗](https://huggingface.co/spaces) using [Gradio](https://github.com/gradio-app/gradio). Try out the Web Demo\n\n[![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/yizhangliu/chatGPT)\n\n\u003cp align=\"center\"\u003eChatting\u003c/p\u003e\n\n![Screenshot 1](https://media.discordapp.net/attachments/1038565125482881027/1049255804366237736/image.png)\n\n[//]: # (Italic centred text saying screenshots)\n\u003cp align=\"center\"\u003eCreating a token\u003c/p\u003e\n\n![Screenshot 2](https://media.discordapp.net/attachments/1038565125482881027/1049072247442264094/image.png?width=2468\u0026height=885)\n\n```\nYou: Hi there, My name is Rawa\nChat GPT: Hello Rawa, nice to meet you. Is there something you would like to talk about or ask me? I'm here to help with any questions you may have.\nYou: great, now say my name like Heisenberg\nChat GPT: Sure, Rawa like Heisenberg. Is there anything else you would like to talk about? I'm here to help with any questions you may have.\nYou: Sorry I meant like the episode of Breaking Bad where Walter White says Heisenberg\nChat GPT: Ah, I see. In that case, you could try saying it like this: \"My name is Rawa, like Heisenberg.\" This is a reference to the character Walter White from the TV show Breaking Bad, who often used the pseudonym \"Heisenberg\" when conducting illegal activities. The character was known for his cool and calculated demeanor, so saying your name like Heisenberg in this context would mean saying it with confidence and authority.\n ```\n\n## Install\n```\npip install chatgptpy --upgrade\n```\n\n## Usage\n[**NEW**] Pass a `options()` object to the `ChatGPT()` constructor to customize the session\n\n[**NEW**] You can now save your conversations to a file\n\n```python\nfrom pychatgpt import Chat, Options\n\noptions = Options()\n\n# [New] Pass Moderation. https://github.com/rawandahmad698/PyChatGPT/discussions/103\n# options.pass_moderation = False\n\n# [New] Enable, Disable logs\noptions.log = True\n\n# Track conversation\noptions.track = True \n\n# Use a proxy\noptions.proxies = 'http://localhost:8080'\n\n# Optionally, you can pass a file path to save the conversation\n# They're created if they don't exist\n\n# options.chat_log = \"chat_log.txt\"\n# options.id_log = \"id_log.txt\"\n\n# Create a Chat object\nchat = Chat(email=\"email\", password=\"password\", options=options)\nanswer = chat.ask(\"How are you?\")\nprint(answer)\n```\n\n[**NEW**] Resume a conversation\n```python\nfrom pychatgpt import Chat\n\n# Create a Chat object\nchat = Chat(email=\"email\", password=\"password\", \n            conversation_id=\"Parent Conversation ID\", \n            previous_convo_id=\"Previous Conversation ID\")\n\nanswer, parent_conversation_id, conversation_id = chat.ask(\"How are you?\")\n\nprint(answer)\n\n# Or change the conversation id later\nanswer, _, _ = chat.ask(\"How are you?\", \n                        previous_convo_id=\"Parent Conversation ID\",\n                        conversation_id=\"Previous Conversation ID\")\nprint(answer)\n\n```\nStart a CLI Session\n```python\nfrom pychatgpt import Chat\n\nchat = Chat(email=\"email\", password=\"password\")\nchat.cli_chat()\n```\n\nAsk a one time question\n```python\nfrom pychatgpt import Chat\n\n# Initializing the chat class will automatically log you in, check access_tokens\nchat = Chat(email=\"email\", password=\"password\") \nanswer, parent_conversation_id, conversation_id = chat.ask(\"Hello!\")\n```\n\n#### You could also manually set, get the token\n```python\nimport time\nfrom pychatgpt import OpenAI\n\n# Manually set the token\nOpenAI.Auth(email_address=\"email\", password=\"password\").save_access_token(access_token=\"\", expiry=time.time() + 3600)\n\n# Get the token, expiry\naccess_token, expiry = OpenAI.get_access_token()\n\n# Check if the token is valid\nis_expired = OpenAI.token_expired() # Returns True or False\n```\n[//]: # (Add A changelog here)\n\u003cdetails\u003e\u003csummary\u003eChange Log\u003c/summary\u003e\n\n#### Update using `pip install chatgptpy --upgrade`\n\n#### 1.0.8\n- Fixes an issue when reading from id_log.txt\n- Introduces a new `pass_moderation` parameter to the `options()` class, defaults to `False`\n- Adds proxies to moderation.\n- If `pass_moderation` is True, the function is invoked in another thread, so it doesn't block the main thread.\n\n#### 1.0.7\n- Make a request to the mod endpoint first, otherwise a crippled version of the response is returned\n\n#### 1.0.6\n- New option to turn off logs. \n- Better Error handling.\n- Enhanced conversation tracking\n- Ask now returns a tuple of `answer, previous_convo, convo_id` \n- Better docs\n\n#### 1.0.5\n- Pull requests/minor fixes\n\n#### 1.0.4\n- Fixes for part 8 of token authentication\n\n#### 1.0.3 \n- a new `options()` class method to set the options for the chat session\n- save the conversation to a file\n- resume the conversation even after closing the program\n\n\n#### 1.0.2\n- ChatGPT API switches from `action=next` to `action=variant`, frequently. This library is now using `action=variant` instead of `action=next` to get the next response from the API.\n- Sometimes when the server is overloaded, the API returns a `502 Bad Gateway` error.\n- Added Error handling if the auth.json file is not found/corrupt\n\n#### 1.0.0\n- Initial Release via PyPi\n\u003c/details\u003e\n\n### Other notes\nIf the token creation process is failing:\n1. Try to use a proxy (I recommend using this always)\n2. Don't try to log in too fast. At least wait 10 minutes if you're being rate limited.\n3. If you're still having issues, try to use a VPN. On a VPN, the script should work fine.\n\n\n### What's next?\nI'm planning to add a few more features, such as:\n- [x] A python module that can be imported and used in other projects\n- [x] A way to save the conversation\n- [ ] Better error handling\n- [ ] Multi-user chatting\n\n### The whole process\nI have been looking for a way to interact with the new Chat GPT API, but most of the sources here on GitHub \nrequire you to have a Chromium instance running in the background. or by using the Web Inspector to grab Access Token manually.\n\nNo more. I have been able to reverse engineer the API and use a TLS client to mimic a real user, allowing the script to login without setting off any bot detection techniques by Auth0\n\nBasically, the script logs in on your behalf, using a TLS client, then grabs the Access Token. It's pretty fast.\n\nFirst, I'd like to tell you that \"just making http\" requests is not going to be enough, Auth0 is smart, each process is guarded by a \n`state` token, which is a JWT token. This token is used to prevent CSRF attacks, and it's also used to prevent bots from logging in.\nIf you look at the `auth.py` file, there are over nine functions, each one of them is responsible for a different task, and they all\nwork together to create a token for you. `allow-redirects` played a huge role in this, as it allowed to navigate through the login process\n\nI work at MeshMonitors.io, We make amazing tools (Check it out yo!). I decided not to spend too much time on this, but here we are.\n\n### Why did I do this?\nNo one has been able to do this, and I wanted to see if I could.\n\n### Credits\n- [OpenAI](https://openai.com/) for creating the ChatGPT API\n- [FlorianREGAZ](https://github.com/FlorianREGAZ) for the TLS Client\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frawandahmad698%2Fpychatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frawandahmad698%2Fpychatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frawandahmad698%2Fpychatgpt/lists"}