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.4.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.4-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chat_deepseek_api-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 0b26d94dacfecda1218d786b1a558ba96b41538e370c84970151d95839381e97
MD5 b750528eaf1081b96478b6021eb2352a
BLAKE2b-256 8b0189e28901c10c46680e8c5629f6698b4ef95804976a459821d5aa4968a78e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for chat_deepseek_api-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 43182901f06aa7dbc7a32addf9c8756764c54d8f36645a0384acf991dd6d0dcd
MD5 bb42b660edf109c68cba5249c97a4844
BLAKE2b-256 036d9cea2d3187f50725b50a8ee541e4e65d1e55fe66d320e4210c5bf5768ec2

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