dify-api-client 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 haoyuhu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: dify-api-client
3
+ Version: 0.0.1
4
+ Summary: dify-api-client - A package for interacting with the Dify Service-API
5
+ Author-email: lucas <lucas@castalk.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 haoyuhu
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE.md
28
+ Keywords: dify-api,dify-client
29
+ Classifier: Operating System :: OS Independent
30
+ Classifier: Programming Language :: Python :: 3
31
+ Requires-Python: >=3.10
32
+ Requires-Dist: httpx-sse>=0.4.0
33
+ Requires-Dist: httpx>=0.28.1
34
+ Requires-Dist: pydantic>=2.10.4
35
+ Provides-Extra: adv
36
+ Provides-Extra: all
37
+ Requires-Dist: pre-commit; extra == 'all'
38
+ Requires-Dist: pylint; extra == 'all'
39
+ Requires-Dist: pytest; extra == 'all'
40
+ Requires-Dist: ruff>=0.8.0; extra == 'all'
41
+ Provides-Extra: dev
42
+ Requires-Dist: pre-commit; extra == 'dev'
43
+ Requires-Dist: pylint; extra == 'dev'
44
+ Requires-Dist: pytest; extra == 'dev'
45
+ Requires-Dist: ruff>=0.8.0; extra == 'dev'
46
+ Description-Content-Type: text/markdown
47
+
48
+ # dify-api-client
49
+
50
+ This package is a fork of [`dify-client-python`](https://github.com/haoyuhu/dify-client-python) with custom modifications
51
+
52
+ It provides a convenient and powerful interface to interact with the Dify API, supporting both synchronous and asynchronous operations.
53
+
54
+ ## Main Features
55
+
56
+ * **Synchronous and Asynchronous Support**: The client offers both synchronous and asynchronous methods, allowing for
57
+ flexible integration into various Python codebases and frameworks.
58
+ * **Stream and Non-stream Support**: Seamlessly work with both streaming and non-streaming endpoints of the Dify API for
59
+ real-time and batch processing use cases.
60
+ * **Comprehensive Endpoint Coverage**: Support completion, chat, workflows, feedback, file uploads, etc., the client
61
+ covers all available Dify API endpoints.
62
+
63
+
64
+ ## Quick Start
65
+ ### Sync
66
+ Here's a quick example of how you can use the `DifyClient` to send a chat message.
67
+
68
+ ```python
69
+ import uuid
70
+ from dify_client import DifyClient, models
71
+
72
+ # Initialize the client with your API key
73
+ client = DifyClient(
74
+ api_key="your-api-key",
75
+ api_base="http://localhost/v1",
76
+ )
77
+ user = str(uuid.uuid4())
78
+
79
+ # Create a blocking chat request
80
+ blocking_chat_req = models.ChatRequest(
81
+ query="Hi, dify-client-python!",
82
+ inputs={"city": "Beijing"},
83
+ user=user,
84
+ response_mode=models.ResponseMode.BLOCKING,
85
+ )
86
+
87
+ # Send the chat message
88
+ chat_response = client.chat_messages(blocking_chat_req, timeout=60.)
89
+ print(chat_response)
90
+
91
+ # Create a streaming chat request
92
+ streaming_chat_req = models.ChatRequest(
93
+ query="Hi, dify-client-python!",
94
+ inputs={"city": "Beijing"},
95
+ user=user,
96
+ response_mode=models.ResponseMode.STREAMING,
97
+ )
98
+
99
+ # Send the chat message
100
+ for chunk in client.chat_messages(streaming_chat_req, timeout=60.):
101
+ print(chunk)
102
+ ```
103
+
104
+ ### Async
105
+ For asynchronous operations, use the `AsyncDifyClient` in a similar fashion:
106
+
107
+ ```python
108
+ import asyncio
109
+ import uuid
110
+
111
+ from dify_client import AsyncDifyClient, models
112
+ # Initialize the async client with your API key
113
+ async_client = AsyncDifyClient(
114
+ api_key="your-api-key",
115
+ api_base="http://localhost/v1",
116
+ )
117
+
118
+
119
+ # Define an asynchronous function to send a blocking chat message with BLOCKING ResponseMode
120
+ async def send_chat_message():
121
+ user = str(uuid.uuid4())
122
+ # Create a blocking chat request
123
+ blocking_chat_req = models.ChatRequest(
124
+ query="Hi, dify-client-python!",
125
+ inputs={"city": "Beijing"},
126
+ user=user,
127
+ response_mode=models.ResponseMode.BLOCKING,
128
+ )
129
+ chat_response = await async_client.achat_messages(blocking_chat_req, timeout=60.)
130
+ print(chat_response)
131
+
132
+
133
+ # Define an asynchronous function to send a chat message with STREAMING ResponseMode
134
+ async def send_chat_message_stream():
135
+ user = str(uuid.uuid4())
136
+ # Create a blocking chat request
137
+ streaming_chat_req = models.ChatRequest(
138
+ query="Hi, dify-client-python!",
139
+ inputs={"city": "Beijing"},
140
+ user=user,
141
+ response_mode=models.ResponseMode.STREAMING,
142
+ )
143
+ async for chunk in await async_client.achat_messages(streaming_chat_req, timeout=60.):
144
+ print(chunk)
145
+
146
+
147
+ # Run the asynchronous function
148
+ asyncio.gather(send_chat_message(), send_chat_message_stream())
149
+ ```
@@ -0,0 +1,102 @@
1
+ # dify-api-client
2
+
3
+ This package is a fork of [`dify-client-python`](https://github.com/haoyuhu/dify-client-python) with custom modifications
4
+
5
+ It provides a convenient and powerful interface to interact with the Dify API, supporting both synchronous and asynchronous operations.
6
+
7
+ ## Main Features
8
+
9
+ * **Synchronous and Asynchronous Support**: The client offers both synchronous and asynchronous methods, allowing for
10
+ flexible integration into various Python codebases and frameworks.
11
+ * **Stream and Non-stream Support**: Seamlessly work with both streaming and non-streaming endpoints of the Dify API for
12
+ real-time and batch processing use cases.
13
+ * **Comprehensive Endpoint Coverage**: Support completion, chat, workflows, feedback, file uploads, etc., the client
14
+ covers all available Dify API endpoints.
15
+
16
+
17
+ ## Quick Start
18
+ ### Sync
19
+ Here's a quick example of how you can use the `DifyClient` to send a chat message.
20
+
21
+ ```python
22
+ import uuid
23
+ from dify_client import DifyClient, models
24
+
25
+ # Initialize the client with your API key
26
+ client = DifyClient(
27
+ api_key="your-api-key",
28
+ api_base="http://localhost/v1",
29
+ )
30
+ user = str(uuid.uuid4())
31
+
32
+ # Create a blocking chat request
33
+ blocking_chat_req = models.ChatRequest(
34
+ query="Hi, dify-client-python!",
35
+ inputs={"city": "Beijing"},
36
+ user=user,
37
+ response_mode=models.ResponseMode.BLOCKING,
38
+ )
39
+
40
+ # Send the chat message
41
+ chat_response = client.chat_messages(blocking_chat_req, timeout=60.)
42
+ print(chat_response)
43
+
44
+ # Create a streaming chat request
45
+ streaming_chat_req = models.ChatRequest(
46
+ query="Hi, dify-client-python!",
47
+ inputs={"city": "Beijing"},
48
+ user=user,
49
+ response_mode=models.ResponseMode.STREAMING,
50
+ )
51
+
52
+ # Send the chat message
53
+ for chunk in client.chat_messages(streaming_chat_req, timeout=60.):
54
+ print(chunk)
55
+ ```
56
+
57
+ ### Async
58
+ For asynchronous operations, use the `AsyncDifyClient` in a similar fashion:
59
+
60
+ ```python
61
+ import asyncio
62
+ import uuid
63
+
64
+ from dify_client import AsyncDifyClient, models
65
+ # Initialize the async client with your API key
66
+ async_client = AsyncDifyClient(
67
+ api_key="your-api-key",
68
+ api_base="http://localhost/v1",
69
+ )
70
+
71
+
72
+ # Define an asynchronous function to send a blocking chat message with BLOCKING ResponseMode
73
+ async def send_chat_message():
74
+ user = str(uuid.uuid4())
75
+ # Create a blocking chat request
76
+ blocking_chat_req = models.ChatRequest(
77
+ query="Hi, dify-client-python!",
78
+ inputs={"city": "Beijing"},
79
+ user=user,
80
+ response_mode=models.ResponseMode.BLOCKING,
81
+ )
82
+ chat_response = await async_client.achat_messages(blocking_chat_req, timeout=60.)
83
+ print(chat_response)
84
+
85
+
86
+ # Define an asynchronous function to send a chat message with STREAMING ResponseMode
87
+ async def send_chat_message_stream():
88
+ user = str(uuid.uuid4())
89
+ # Create a blocking chat request
90
+ streaming_chat_req = models.ChatRequest(
91
+ query="Hi, dify-client-python!",
92
+ inputs={"city": "Beijing"},
93
+ user=user,
94
+ response_mode=models.ResponseMode.STREAMING,
95
+ )
96
+ async for chunk in await async_client.achat_messages(streaming_chat_req, timeout=60.):
97
+ print(chunk)
98
+
99
+
100
+ # Run the asynchronous function
101
+ asyncio.gather(send_chat_message(), send_chat_message_stream())
102
+ ```
@@ -0,0 +1,5 @@
1
+ from ._clientx import AsyncDifyClient, DifyClient
2
+
3
+
4
+ __version__ = "0.0.1"
5
+ __all__ = ["DifyClient", "AsyncDifyClient"]