dify-client-python


Namedify-client-python JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/haoyuhu/dify-client-python
SummaryA package for interacting with the Dify Service-API
upload_time2024-04-27 04:00:26
maintainerNone
docs_urlNone
authorhaoyuhu
requires_python>=3.7
licenseMIT
keywords dify nlp ai language-processing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dify-client-python

Welcome to the `dify-client-python` repository! This Python package provides a convenient and powerful interface to
interact with the Dify API, enabling developers to integrate a wide range of features into their applications with ease.

## Main Features

* **Synchronous and Asynchronous Support**: The client offers both synchronous and asynchronous methods, allowing for
  flexible integration into various Python codebases and frameworks.
* **Stream and Non-stream Support**: Seamlessly work with both streaming and non-streaming endpoints of the Dify API for
  real-time and batch processing use cases.
* **Comprehensive Endpoint Coverage**: Support completion, chat, workflows, feedback, file uploads, etc., the client
  covers all available Dify API endpoints.

## Installation

Before using the `dify-client-python` client, you'll need to install it. You can easily install it using `pip`:

```bash
pip install dify-client-python
```

## Quick Start

Here's a quick example of how you can use the Dify Client to send a chat message.

```python
import uuid
from dify_client import Client, models

# Initialize the client with your API key
client = Client(
    api_key="your-api-key",
    api_base="http://localhost/v1",
)
user = str(uuid.uuid4())

# Create a blocking chat request
blocking_chat_req = models.ChatRequest(
    query="Hi, dify-client-python!",
    inputs={"city": "Beijing"},
    user=user,
    response_mode=models.ResponseMode.BLOCKING,
)

# Send the chat message
chat_response = client.chat_messages(blocking_chat_req, timeout=60.)
print(chat_response)

# Create a streaming chat request
streaming_chat_req = models.ChatRequest(
    query="Hi, dify-client-python!",
    inputs={"city": "Beijing"},
    user=user,
    response_mode=models.ResponseMode.STREAMING,
)

# Send the chat message
for chunk in client.chat_messages(streaming_chat_req, timeout=60.):
    print(chunk)
```

For asynchronous operations, use the `AsyncClient` in a similar fashion:

```python
import asyncio
import uuid

from dify_client import AsyncClient, models

# Initialize the async client with your API key
async_client = AsyncClient(
    api_key="your-api-key",
    api_base="http://localhost/v1",
)


# Define an asynchronous function to send a blocking chat message with BLOCKING ResponseMode
async def send_chat_message():
    user = str(uuid.uuid4())
    # Create a blocking chat request
    blocking_chat_req = models.ChatRequest(
        query="Hi, dify-client-python!",
        inputs={"city": "Beijing"},
        user=user,
        response_mode=models.ResponseMode.BLOCKING,
    )
    chat_response = await async_client.achat_messages(blocking_chat_req, timeout=60.)
    print(chat_response)


# Define an asynchronous function to send a chat message with STREAMING ResponseMode
async def send_chat_message_stream():
    user = str(uuid.uuid4())
    # Create a blocking chat request
    streaming_chat_req = models.ChatRequest(
        query="Hi, dify-client-python!",
        inputs={"city": "Beijing"},
        user=user,
        response_mode=models.ResponseMode.STREAMING,
    )
    async for chunk in await async_client.achat_messages(streaming_chat_req, timeout=60.):
        print(chunk)


# Run the asynchronous function
asyncio.gather(send_chat_message(), send_chat_message_stream())
```

## Documentation

For detailed information on all the functionalities and how to use each endpoint, please refer to the official Dify API
documentation. This will provide you with comprehensive guidance on request and response structures, error handling, and
other important details.

## Contributing

Contributions are welcome! If you would like to contribute to the `dify-client-python`, please feel free to make a pull
request or open an issue to discuss potential changes.

## License

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

```text
MIT License

Copyright (c) 2024 haoyuhu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

```

## Support

If you encounter any issues or have questions regarding the usage of this client, please reach out to the Dify Client
support team.

Happy coding! 🚀

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/haoyuhu/dify-client-python",
    "name": "dify-client-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "dify nlp ai language-processing",
    "author": "haoyuhu",
    "author_email": "im@huhaoyu.com",
    "download_url": "https://files.pythonhosted.org/packages/f0/95/b49699c515bcc5ffcce2355ffd6e7558024d765473da293d535a5b22e64f/dify-client-python-1.0.0.tar.gz",
    "platform": null,
    "description": "# dify-client-python\n\nWelcome to the `dify-client-python` repository! This Python package provides a convenient and powerful interface to\ninteract with the Dify API, enabling developers to integrate a wide range of features into their applications with ease.\n\n## Main Features\n\n* **Synchronous and Asynchronous Support**: The client offers both synchronous and asynchronous methods, allowing for\n  flexible integration into various Python codebases and frameworks.\n* **Stream and Non-stream Support**: Seamlessly work with both streaming and non-streaming endpoints of the Dify API for\n  real-time and batch processing use cases.\n* **Comprehensive Endpoint Coverage**: Support completion, chat, workflows, feedback, file uploads, etc., the client\n  covers all available Dify API endpoints.\n\n## Installation\n\nBefore using the `dify-client-python` client, you'll need to install it. You can easily install it using `pip`:\n\n```bash\npip install dify-client-python\n```\n\n## Quick Start\n\nHere's a quick example of how you can use the Dify Client to send a chat message.\n\n```python\nimport uuid\nfrom dify_client import Client, models\n\n# Initialize the client with your API key\nclient = Client(\n    api_key=\"your-api-key\",\n    api_base=\"http://localhost/v1\",\n)\nuser = str(uuid.uuid4())\n\n# Create a blocking chat request\nblocking_chat_req = models.ChatRequest(\n    query=\"Hi, dify-client-python!\",\n    inputs={\"city\": \"Beijing\"},\n    user=user,\n    response_mode=models.ResponseMode.BLOCKING,\n)\n\n# Send the chat message\nchat_response = client.chat_messages(blocking_chat_req, timeout=60.)\nprint(chat_response)\n\n# Create a streaming chat request\nstreaming_chat_req = models.ChatRequest(\n    query=\"Hi, dify-client-python!\",\n    inputs={\"city\": \"Beijing\"},\n    user=user,\n    response_mode=models.ResponseMode.STREAMING,\n)\n\n# Send the chat message\nfor chunk in client.chat_messages(streaming_chat_req, timeout=60.):\n    print(chunk)\n```\n\nFor asynchronous operations, use the `AsyncClient` in a similar fashion:\n\n```python\nimport asyncio\nimport uuid\n\nfrom dify_client import AsyncClient, models\n\n# Initialize the async client with your API key\nasync_client = AsyncClient(\n    api_key=\"your-api-key\",\n    api_base=\"http://localhost/v1\",\n)\n\n\n# Define an asynchronous function to send a blocking chat message with BLOCKING ResponseMode\nasync def send_chat_message():\n    user = str(uuid.uuid4())\n    # Create a blocking chat request\n    blocking_chat_req = models.ChatRequest(\n        query=\"Hi, dify-client-python!\",\n        inputs={\"city\": \"Beijing\"},\n        user=user,\n        response_mode=models.ResponseMode.BLOCKING,\n    )\n    chat_response = await async_client.achat_messages(blocking_chat_req, timeout=60.)\n    print(chat_response)\n\n\n# Define an asynchronous function to send a chat message with STREAMING ResponseMode\nasync def send_chat_message_stream():\n    user = str(uuid.uuid4())\n    # Create a blocking chat request\n    streaming_chat_req = models.ChatRequest(\n        query=\"Hi, dify-client-python!\",\n        inputs={\"city\": \"Beijing\"},\n        user=user,\n        response_mode=models.ResponseMode.STREAMING,\n    )\n    async for chunk in await async_client.achat_messages(streaming_chat_req, timeout=60.):\n        print(chunk)\n\n\n# Run the asynchronous function\nasyncio.gather(send_chat_message(), send_chat_message_stream())\n```\n\n## Documentation\n\nFor detailed information on all the functionalities and how to use each endpoint, please refer to the official Dify API\ndocumentation. This will provide you with comprehensive guidance on request and response structures, error handling, and\nother important details.\n\n## Contributing\n\nContributions are welcome! If you would like to contribute to the `dify-client-python`, please feel free to make a pull\nrequest or open an issue to discuss potential changes.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n```text\nMIT License\n\nCopyright (c) 2024 haoyuhu\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n```\n\n## Support\n\nIf you encounter any issues or have questions regarding the usage of this client, please reach out to the Dify Client\nsupport team.\n\nHappy coding! \ud83d\ude80\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A package for interacting with the Dify Service-API",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/haoyuhu/dify-client-python"
    },
    "split_keywords": [
        "dify",
        "nlp",
        "ai",
        "language-processing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "039f034b3a358e3b0da1df5a24095c2e2f69660c6caa03906cdfabc1d5813f50",
                "md5": "01dffa4c8861cd43691859601b6875be",
                "sha256": "1641142c06e698011bef914909d395fac022fc812466fc4e47947870a7d46393"
            },
            "downloads": -1,
            "filename": "dify_client_python-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01dffa4c8861cd43691859601b6875be",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 14979,
            "upload_time": "2024-04-27T04:00:23",
            "upload_time_iso_8601": "2024-04-27T04:00:23.722543Z",
            "url": "https://files.pythonhosted.org/packages/03/9f/034b3a358e3b0da1df5a24095c2e2f69660c6caa03906cdfabc1d5813f50/dify_client_python-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f095b49699c515bcc5ffcce2355ffd6e7558024d765473da293d535a5b22e64f",
                "md5": "3940f03ec2d844d3f22194bb822049bc",
                "sha256": "202cf887d58176a5ea3157a72e917d50c15b000200ca06345e74f931adc192e8"
            },
            "downloads": -1,
            "filename": "dify-client-python-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3940f03ec2d844d3f22194bb822049bc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13484,
            "upload_time": "2024-04-27T04:00:26",
            "upload_time_iso_8601": "2024-04-27T04:00:26.015468Z",
            "url": "https://files.pythonhosted.org/packages/f0/95/b49699c515bcc5ffcce2355ffd6e7558024d765473da293d535a5b22e64f/dify-client-python-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 04:00:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "haoyuhu",
    "github_project": "dify-client-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dify-client-python"
}
        
Elapsed time: 0.23433s