# dify-oapi
A Dify App Service-API Client, using for build a webapp by request Service-API
## Usage
First, install `dify-oapi` python sdk package:
```
pip install dify-oapi
```
Write your code with sdk:
- chat generate with `blocking` response_mode
```python
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
from dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody
from dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile
from dify_oapi.client import Client
from dify_oapi.core.model.request_option import RequestOption
def main():
client = Client.builder().domain("https://api.dify.ai").build()
req_file = (
ChatRequestFile.builder()
.type("image")
.transfer_method("remote_url")
.url("https://cloud.dify.ai/logo/logo-site.png")
.build()
)
req_body = (
ChatRequestBody.builder()
.inputs({})
.query("What are the specs of the iPhone 13 Pro Max?")
.response_mode("blocking")
.conversation_id("")
.user("abc-123")
.files([req_file])
.build()
)
req = ChatRequest.builder().request_body(req_body).build()
req_option = RequestOption.builder().api_key("<your-api-key>").build()
response = client.chat.v1.chat.chat(req, req_option, False)
# response = await client.chat.v1.chat.achat(req, req_option, False)
print(response.success)
print(response.code)
print(response.msg)
print(response.answer)
if __name__ == "__main__":
main()
```
- chat generate with `streaming` response_mode
```python
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
from dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody
from dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile
from dify_oapi.client import Client
from dify_oapi.core.model.request_option import RequestOption
def main():
client = Client.builder().domain("https://api.dify.ai").build()
req_file = (
ChatRequestFile.builder()
.type("image")
.transfer_method("remote_url")
.url("https://cloud.dify.ai/logo/logo-site.png")
.build()
)
req_body = (
ChatRequestBody.builder()
.inputs({})
.query("What are the specs of the iPhone 13 Pro Max?")
.response_mode("streaming")
.conversation_id("")
.user("abc-123")
.files([req_file])
.build()
)
req = ChatRequest.builder().request_body(req_body).build()
req_option = RequestOption.builder().api_key("<your-api-key>").build()
response = client.chat.v1.chat.chat(req, req_option, True)
# response = await client.chat.v1.chat.achat(req, req_option, True)
for chunk in response:
print(chunk)
if __name__ == "__main__":
main()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/QiMington/dify-oapi",
"name": "dify-oapi",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "dify, nlp, ai, language-processing",
"author": "QiMington",
"author_email": "qimington@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d4/1b/52198462146ec956c5005e804e95cd19b5249cf41c41afe7ccc58200f735/dify_oapi-0.0.14.tar.gz",
"platform": null,
"description": "# dify-oapi\n\nA Dify App Service-API Client, using for build a webapp by request Service-API\n\n## Usage\n\nFirst, install `dify-oapi` python sdk package:\n\n```\npip install dify-oapi\n```\n\nWrite your code with sdk:\n\n- chat generate with `blocking` response_mode\n\n```python\nfrom dify_oapi.api.chat.v1.model.chat_request import ChatRequest\nfrom dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody\nfrom dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile\nfrom dify_oapi.client import Client\nfrom dify_oapi.core.model.request_option import RequestOption\n\ndef main():\n client = Client.builder().domain(\"https://api.dify.ai\").build()\n req_file = (\n ChatRequestFile.builder()\n .type(\"image\")\n .transfer_method(\"remote_url\")\n .url(\"https://cloud.dify.ai/logo/logo-site.png\")\n .build()\n )\n req_body = (\n ChatRequestBody.builder()\n .inputs({})\n .query(\"What are the specs of the iPhone 13 Pro Max?\")\n .response_mode(\"blocking\")\n .conversation_id(\"\")\n .user(\"abc-123\")\n .files([req_file])\n .build()\n )\n req = ChatRequest.builder().request_body(req_body).build()\n req_option = RequestOption.builder().api_key(\"<your-api-key>\").build()\n response = client.chat.v1.chat.chat(req, req_option, False)\n # response = await client.chat.v1.chat.achat(req, req_option, False)\n print(response.success)\n print(response.code)\n print(response.msg)\n print(response.answer)\n\n\nif __name__ == \"__main__\":\n main()\n\n```\n\n- chat generate with `streaming` response_mode\n\n```python\nfrom dify_oapi.api.chat.v1.model.chat_request import ChatRequest\nfrom dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody\nfrom dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile\nfrom dify_oapi.client import Client\nfrom dify_oapi.core.model.request_option import RequestOption\n\ndef main():\n client = Client.builder().domain(\"https://api.dify.ai\").build()\n req_file = (\n ChatRequestFile.builder()\n .type(\"image\")\n .transfer_method(\"remote_url\")\n .url(\"https://cloud.dify.ai/logo/logo-site.png\")\n .build()\n )\n req_body = (\n ChatRequestBody.builder()\n .inputs({})\n .query(\"What are the specs of the iPhone 13 Pro Max?\")\n .response_mode(\"streaming\")\n .conversation_id(\"\")\n .user(\"abc-123\")\n .files([req_file])\n .build()\n )\n req = ChatRequest.builder().request_body(req_body).build()\n req_option = RequestOption.builder().api_key(\"<your-api-key>\").build()\n response = client.chat.v1.chat.chat(req, req_option, True)\n # response = await client.chat.v1.chat.achat(req, req_option, True)\n for chunk in response:\n print(chunk)\n\n\nif __name__ == \"__main__\":\n main()\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A package for interacting with the Dify Service-API",
"version": "0.0.14",
"project_urls": {
"Homepage": "https://github.com/QiMington/dify-oapi",
"Source": "https://github.com/QiMington/dify-oapi"
},
"split_keywords": [
"dify",
" nlp",
" ai",
" language-processing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "be56b6c6e2cd9e6ca414b7483fe289c3f53002a4f7d48fc957ff38713f5b3286",
"md5": "8d54bce72d5a9b59280a69d4aa32e27a",
"sha256": "d84830d575ee94ff229373580eae17f6db894ab867459a864132cc9507411ce4"
},
"downloads": -1,
"filename": "dify_oapi-0.0.14-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8d54bce72d5a9b59280a69d4aa32e27a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 89502,
"upload_time": "2025-07-24T03:52:21",
"upload_time_iso_8601": "2025-07-24T03:52:21.222272Z",
"url": "https://files.pythonhosted.org/packages/be/56/b6c6e2cd9e6ca414b7483fe289c3f53002a4f7d48fc957ff38713f5b3286/dify_oapi-0.0.14-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d41b52198462146ec956c5005e804e95cd19b5249cf41c41afe7ccc58200f735",
"md5": "1ae73910031502a0beaf813cf2f6920a",
"sha256": "4808b748e9878c38de320ddf52de21d15d9639e1942b781f62e332fb1c8bed31"
},
"downloads": -1,
"filename": "dify_oapi-0.0.14.tar.gz",
"has_sig": false,
"md5_digest": "1ae73910031502a0beaf813cf2f6920a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 32400,
"upload_time": "2025-07-24T03:52:22",
"upload_time_iso_8601": "2025-07-24T03:52:22.677369Z",
"url": "https://files.pythonhosted.org/packages/d4/1b/52198462146ec956c5005e804e95cd19b5249cf41c41afe7ccc58200f735/dify_oapi-0.0.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 03:52:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "QiMington",
"github_project": "dify-oapi",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "dify-oapi"
}