Skip to main content

An unofficial Python API wrapper for chat.deepseek.com

Project description

Deepseek coder Reverse Engineered API Wrapper

Unofficial API Wrapper for Deepseek (chat.deepseek.com) in Python. This is a reverse-engineered API for the Deepseek coder and Deepseek code chatbots. This API is not affiliated with Deepseek in any way.

This repository is inpired by deepseek-api. The original repository is not maintained anymore, so I decided to create a new one.

Installation

pip install git+https://github.com/thinhdanggroup/chat-deepseek-api

Usage

Asynchronous CLI Example

Copy file .env.example to .env and fill in your Deepseek email, password, device id, cookies, and ds_pow_response.

DEEPSEEK_EMAIL=
DEEPSEEK_PASSWORD=
DEEPSEEK_DEVICE_ID=
DEEPSEEK_COOKIES=
DEEPSEEK_DS_POW_RESPONSE=

Sample code:

import asyncio
import os
from deepseek_api import DeepseekAPI
from dotenv import load_dotenv

from deepseek_api.model import MessageData

load_dotenv()


async def main():
    email = os.environ.get("DEEPSEEK_EMAIL") # Your Deepseek email
    password = os.environ.get("DEEPSEEK_PASSWORD") # Your Deepseek password
    device_id = os.environ.get("DEEPSEEK_DEVICE_ID") # Your Deepseek device id
    cookies = os.environ.get("DEEPSEEK_COOKIES") # Your Deepseek cookies. You can get it by login to Deepseek and copy the cookies from the browser
    ds_pow_response = os.environ.get("DEEPSEEK_DS_POW_RESPONSE") # Your Deepseek ds_pow_response. You can get it by login to Deepseek and copy the ds_pow_response from the network tab in the browser

    app = await DeepseekAPI.create(
        email=email,
        password=password,
        save_login=True,
        device_id=device_id,
        custom_headers={
            "cookie": cookies,
            "x-ds-pow-response": ds_pow_response,
        },
    )
    chat_session_id = await app.new_chat()

    print(f"Starting chat session with id: {chat_session_id}")

    message_id = None
    async for chunk in app.chat(
        message="who are you", id=chat_session_id, parent_message_id=message_id
    ):
        chunk_data: MessageData = chunk
        print(chunk_data.choices[0].delta.content, end="")

        cur_message_id = chunk.get_message_id()
        if not cur_message_id:
            cur_message_id = 0
        if not message_id or cur_message_id > message_id:
            message_id = cur_message_id

    print()
    
    async for chunk in app.chat(
        message="what can you do", id=chat_session_id, parent_message_id=message_id
    ):
        chunk_data: MessageData = chunk
        print(chunk_data.choices[0].delta.content, end="")

        cur_message_id = chunk.get_message_id()
        if cur_message_id > message_id:
            message_id = cur_message_id

    print()
    await app.close()


if __name__ == "__main__":
    asyncio.run(main()) 

Output:

  chat-deepseek-api
 git:(main)  python examples/simple_app.py
Starting chat session with id: 84ad4e3c-2cfc-45b1-9b84-61dcccd500af
Greetings! I'm DeepSeek-V3, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.
As an AI assistant, I can help answer questions, provide information, and have great conversations with you. Feel free to chat with me about any topic you'd like!

Enjoy!

The example file can be found here

License

CC BY-NC-SA 4.0

Disclaimer

This project is not affiliated with Deepseek in any way. Use at your own risk. This project was created for educational purposes only.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

chat_deepseek_api-0.1.3.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

chat_deepseek_api-0.1.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file chat_deepseek_api-0.1.3.tar.gz.

File metadata

  • Download URL: chat_deepseek_api-0.1.3.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for chat_deepseek_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 65f6f7474b393d6d57c98ccafda0ce11850319978ce37d3487a8b705fd3e5551
MD5 f1b8397f948931abcbb284bd323602dd
BLAKE2b-256 ef53327369860cd9d65db396cb76aeeba06af92fc80fbc600322530785fe33b1

See more details on using hashes here.

File details

Details for the file chat_deepseek_api-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for chat_deepseek_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4344faca09cdfcb06c104684d8119cb7eae4682db04a29cf8ce9bd989bf333b1
MD5 bf622fedeefa3fbec59230d248310ee0
BLAKE2b-256 1eda99270608df3de4a407f25e18784b3b6dd060c937fd540cfc7e138089f2ff

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