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.2.tar.gz (24.2 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.2-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chat_deepseek_api-0.1.2.tar.gz
  • Upload date:
  • Size: 24.2 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.2.tar.gz
Algorithm Hash digest
SHA256 d06d17815954144ca755fb2ebf55bad9807ec2b8c74dfff34ec309f165539749
MD5 612cf970f45c907854788c235e8f485a
BLAKE2b-256 b9140154ee540253638f50c8de4beace552d4d33ad0ae12eb251c55986b65e7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for chat_deepseek_api-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 172d0c861ff7044687e7f73bd5b4d7082d7f14f69ac1e2f63f5f829dd65407bd
MD5 9612de23a12bce064cbb8247c07958de
BLAKE2b-256 bcc4351de7596745de3f613e2d2ea1c493594db170c4101612103dfb129774f5

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