dify-oapi2 1.0.1__py3-none-any.whl → 1.0.2__py3-none-any.whl
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.
- dify_oapi2-1.0.2.dist-info/METADATA +395 -0
- {dify_oapi2-1.0.1.dist-info → dify_oapi2-1.0.2.dist-info}/RECORD +4 -4
- dify_oapi2-1.0.1.dist-info/METADATA +0 -367
- {dify_oapi2-1.0.1.dist-info → dify_oapi2-1.0.2.dist-info}/WHEEL +0 -0
- {dify_oapi2-1.0.1.dist-info → dify_oapi2-1.0.2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,395 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: dify-oapi2
|
3
|
+
Version: 1.0.2
|
4
|
+
Summary: A package for interacting with the Dify Service-API
|
5
|
+
License: MIT
|
6
|
+
License-File: LICENSE
|
7
|
+
Keywords: dify,nlp,ai,language-processing
|
8
|
+
Author: Oscaner Miao
|
9
|
+
Author-email: oscaner1997@gmail.com
|
10
|
+
Requires-Python: >=3.10
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
18
|
+
Requires-Dist: httpx (>=0,<1)
|
19
|
+
Requires-Dist: pydantic (>=2,<3)
|
20
|
+
Project-URL: Homepage, https://github.com/nodite/dify-oapi2
|
21
|
+
Project-URL: Source, https://github.com/nodite/dify-oapi2
|
22
|
+
Description-Content-Type: text/markdown
|
23
|
+
|
24
|
+
# Dify-OAPI
|
25
|
+
|
26
|
+
[](https://badge.fury.io/py/dify-oapi2)
|
27
|
+
[](https://www.python.org/downloads/)
|
28
|
+
[](https://opensource.org/licenses/MIT)
|
29
|
+
|
30
|
+
A modern Python SDK for interacting with the Dify Service-API. This library provides a fluent, type-safe interface for building AI-powered applications using Dify's comprehensive API services including chat, completion, knowledge base, workflow, and chatflow features.
|
31
|
+
|
32
|
+
> This project is based on https://github.com/QiMington/dify-oapi, completely refactored with modern Python practices and full support for the latest Dify API.
|
33
|
+
|
34
|
+
## ✨ Features
|
35
|
+
|
36
|
+
- **Complete API Coverage**: Chat (18 APIs), Chatflow (15 APIs), Completion (10 APIs), Knowledge Base (33 APIs), Workflow (4 APIs), and Core Dify (9 APIs)
|
37
|
+
- **Builder Pattern**: Fluent, chainable interface for constructing requests
|
38
|
+
- **Sync & Async Support**: Both synchronous and asynchronous operations
|
39
|
+
- **Streaming Responses**: Real-time streaming for chat and completion
|
40
|
+
- **Type Safety**: Comprehensive type hints with Pydantic 2.x validation
|
41
|
+
- **File Upload**: Support for images and documents
|
42
|
+
- **Modern HTTP Client**: Built on httpx for reliable API communication
|
43
|
+
- **Connection Pool Optimization**: Efficient TCP connection reuse to reduce resource overhead
|
44
|
+
|
45
|
+
## 📦 Installation
|
46
|
+
|
47
|
+
```bash
|
48
|
+
pip install dify-oapi2
|
49
|
+
```
|
50
|
+
|
51
|
+
**Requirements**: Python 3.10+
|
52
|
+
|
53
|
+
**Core Dependencies**:
|
54
|
+
|
55
|
+
- `pydantic` (^2) - Data validation and settings management with type safety
|
56
|
+
- `httpx` (^0) - Modern async HTTP client
|
57
|
+
|
58
|
+
**Development Dependencies**:
|
59
|
+
|
60
|
+
- `ruff` (^0) - Fast Python linter and formatter
|
61
|
+
- `mypy` (^1) - Static type checking
|
62
|
+
- `pytest` (^8) - Testing framework
|
63
|
+
- `pre-commit` (^4) - Git hooks for code quality
|
64
|
+
- `commitizen` (^4) - Semantic versioning and changelog generation
|
65
|
+
- `poetry` - Dependency management and packaging
|
66
|
+
|
67
|
+
## 🛠️ Technology Stack
|
68
|
+
|
69
|
+
- **Language**: Python 3.10+
|
70
|
+
- **HTTP Client**: httpx with connection pooling optimization
|
71
|
+
- **Type System**: Pydantic 2.x with comprehensive type validation
|
72
|
+
- **Architecture**: Builder pattern with fluent API design + Service layer pattern
|
73
|
+
- **Async Support**: Full async/await support with AsyncGenerator streaming
|
74
|
+
- **Code Quality**: Ruff (linting + formatting) + MyPy (type checking)
|
75
|
+
- **Testing**: pytest with async support and comprehensive coverage
|
76
|
+
- **Packaging**: Poetry with modern Python packaging standards
|
77
|
+
- **Total Coverage**: 89 API methods across 6 services with complete examples
|
78
|
+
|
79
|
+
## 🚀 Quick Start
|
80
|
+
|
81
|
+
### Basic Usage
|
82
|
+
|
83
|
+
```python
|
84
|
+
from dify_oapi.client import Client
|
85
|
+
from dify_oapi.core.model.request_option import RequestOption
|
86
|
+
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
|
87
|
+
|
88
|
+
# Initialize client with builder pattern
|
89
|
+
client = (
|
90
|
+
Client.builder()
|
91
|
+
.domain("https://api.dify.ai")
|
92
|
+
.max_connections(100)
|
93
|
+
.keepalive_expiry(30.0)
|
94
|
+
.build()
|
95
|
+
)
|
96
|
+
|
97
|
+
# Create request options
|
98
|
+
req_option = RequestOption.builder().api_key("your-api-key").build()
|
99
|
+
|
100
|
+
# Use the chat API
|
101
|
+
response = client.chat.chat(
|
102
|
+
request=ChatRequest.builder()
|
103
|
+
.query("Hello, how are you?")
|
104
|
+
.user("user-123")
|
105
|
+
.build(),
|
106
|
+
request_option=req_option
|
107
|
+
)
|
108
|
+
|
109
|
+
print(response.answer)
|
110
|
+
```
|
111
|
+
|
112
|
+
### Comprehensive Examples
|
113
|
+
|
114
|
+
Ready to build AI-powered applications? Check out our comprehensive examples:
|
115
|
+
|
116
|
+
- **[Chat Examples](./examples/chat/)** - Interactive conversations and streaming responses
|
117
|
+
- **[Chatflow Examples](./examples/chatflow/)** - Enhanced chat with workflow events
|
118
|
+
- **[Knowledge Base Examples](./examples/knowledge/)** - Build and query knowledge bases
|
119
|
+
- **[Workflow Examples](./examples/workflow/)** - Automate complex AI workflows
|
120
|
+
- **[Complete Examples Collection](./examples/)** - All API services with detailed usage patterns
|
121
|
+
|
122
|
+
Each example includes complete, runnable code with detailed explanations.
|
123
|
+
|
124
|
+
## 🔧 API Services
|
125
|
+
|
126
|
+
### Chat API (18 APIs)
|
127
|
+
|
128
|
+
**Resources**: annotation (6), chat (3), conversation (6), message (3)
|
129
|
+
|
130
|
+
- **Interactive Chat**: Send messages with blocking/streaming responses
|
131
|
+
- **Conversation Management**: Complete conversation lifecycle operations
|
132
|
+
- **Annotation System**: Create, update, delete annotations with reply settings
|
133
|
+
- **Message Operations**: Basic message handling and history retrieval
|
134
|
+
- **Streaming Support**: Real-time streaming for chat responses
|
135
|
+
- **Type Safety**: Comprehensive type hints with strict Literal types
|
136
|
+
|
137
|
+
### Chatflow API (15 APIs)
|
138
|
+
|
139
|
+
**Resources**: annotation (6), chatflow (3), conversation (6)
|
140
|
+
|
141
|
+
- **Enhanced Chat**: Advanced chat functionality with workflow events
|
142
|
+
- **Conversation Management**: Complete conversation operations with variables
|
143
|
+
- **Annotation System**: Full annotation management and reply configuration
|
144
|
+
- **Workflow Integration**: Seamless integration with workflow events
|
145
|
+
- **Event Streaming**: Real-time streaming with comprehensive event handling
|
146
|
+
- **Type Safety**: Strict Literal types for all predefined values
|
147
|
+
|
148
|
+
### Completion API (10 APIs)
|
149
|
+
|
150
|
+
**Resources**: annotation (6), completion (4)
|
151
|
+
|
152
|
+
- **Text Generation**: Advanced text completion and generation
|
153
|
+
- **Message Processing**: Send messages and control text generation
|
154
|
+
- **Annotation Management**: Create, update, and manage annotations
|
155
|
+
- **Generation Control**: Stop ongoing text generation processes
|
156
|
+
- **Streaming Support**: Real-time text generation with streaming responses
|
157
|
+
- **Type Safety**: Full type validation with Pydantic models
|
158
|
+
|
159
|
+
### Knowledge Base API (33 APIs)
|
160
|
+
|
161
|
+
**Resources**: chunk (4), dataset (6), document (10), model (1), segment (5), tag (7)
|
162
|
+
|
163
|
+
- **Dataset Management**: Complete dataset CRUD operations and content retrieval
|
164
|
+
- **Document Processing**: File upload, text processing, and batch management
|
165
|
+
- **Content Organization**: Fine-grained segmentation and chunk management
|
166
|
+
- **Tag System**: Flexible tagging and categorization system
|
167
|
+
- **Model Integration**: Embedding model information and configuration
|
168
|
+
- **Search & Retrieval**: Advanced search with multiple retrieval strategies
|
169
|
+
|
170
|
+
### Workflow API (4 APIs)
|
171
|
+
|
172
|
+
**Resources**: workflow (4)
|
173
|
+
|
174
|
+
- **Workflow Execution**: Run workflows with blocking or streaming responses
|
175
|
+
- **Execution Control**: Stop running workflows and monitor progress
|
176
|
+
- **Log Management**: Retrieve detailed execution logs and run details
|
177
|
+
- **Parameter Support**: Flexible workflow parameter configuration
|
178
|
+
|
179
|
+
### Dify Core API (9 APIs)
|
180
|
+
|
181
|
+
**Resources**: audio (2), feedback (2), file (1), info (4)
|
182
|
+
|
183
|
+
- **Audio Processing**: Speech-to-text and text-to-speech conversion
|
184
|
+
- **Feedback System**: Submit and retrieve user feedback
|
185
|
+
- **File Management**: Unified file upload and processing
|
186
|
+
- **Application Info**: App configuration, parameters, and metadata access
|
187
|
+
|
188
|
+
## 💡 Examples
|
189
|
+
|
190
|
+
Explore comprehensive examples in the [examples directory](./examples):
|
191
|
+
|
192
|
+
### Chat Examples
|
193
|
+
|
194
|
+
- [**Chat Messages**](./examples/chat/chat/) - Send messages, stop generation, get suggestions
|
195
|
+
- [**Conversation Management**](./examples/chat/conversation/) - Complete conversation operations
|
196
|
+
- [**Message Operations**](./examples/chat/message/) - Basic message operations
|
197
|
+
- [**Annotation Management**](./examples/chat/annotation/) - Annotation CRUD and reply settings
|
198
|
+
|
199
|
+
_Note: File upload and feedback examples are available in [Dify Core API](./examples/dify/) as shared services._
|
200
|
+
|
201
|
+
### Completion Examples
|
202
|
+
|
203
|
+
- [**Completion Operations**](./examples/completion/completion/) - Text generation and completion
|
204
|
+
- [**Annotation Management**](./examples/completion/annotation/) - Annotation operations
|
205
|
+
|
206
|
+
### Knowledge Base Examples
|
207
|
+
|
208
|
+
- [**Dataset Management**](./examples/knowledge/dataset/) - Complete dataset operations
|
209
|
+
- [**Document Processing**](./examples/knowledge/document/) - File upload and text processing
|
210
|
+
- [**Content Organization**](./examples/knowledge/segment/) - Segment and chunk management
|
211
|
+
- [**Tag Management**](./examples/knowledge/tag/) - Metadata and tagging system
|
212
|
+
|
213
|
+
### Chatflow Examples
|
214
|
+
|
215
|
+
- [**Advanced Chat**](./examples/chatflow/chatflow/) - Enhanced chat with streaming and workflow events
|
216
|
+
- [**Conversation Management**](./examples/chatflow/conversation/) - Complete conversation operations
|
217
|
+
- [**Annotation Management**](./examples/chatflow/annotation/) - Annotation CRUD and reply settings
|
218
|
+
|
219
|
+
### Dify Core Examples
|
220
|
+
|
221
|
+
- [**Audio Processing**](./examples/dify/audio/) - Speech-to-text and text-to-speech
|
222
|
+
- [**Feedback Management**](./examples/dify/feedback/) - User feedback collection
|
223
|
+
- [**File Management**](./examples/dify/file/) - File upload and processing
|
224
|
+
- [**Application Info**](./examples/dify/info/) - App configuration and metadata
|
225
|
+
|
226
|
+
### Workflow Examples
|
227
|
+
|
228
|
+
- [**Workflow Operations**](./examples/workflow/workflow/) - Workflow execution and management
|
229
|
+
- [**File Upload**](./examples/workflow/file/) - File upload for workflows
|
230
|
+
|
231
|
+
For detailed examples and usage patterns, see the [examples README](./examples/README.md).
|
232
|
+
|
233
|
+
## 🛠️ Development
|
234
|
+
|
235
|
+
### Prerequisites
|
236
|
+
|
237
|
+
- Python 3.10+
|
238
|
+
- Poetry (for dependency management)
|
239
|
+
- Git (for version control)
|
240
|
+
|
241
|
+
### Setup
|
242
|
+
|
243
|
+
```bash
|
244
|
+
# Clone repository
|
245
|
+
git clone https://github.com/nodite/dify-oapi2.git
|
246
|
+
cd dify-oapi2
|
247
|
+
|
248
|
+
# Setup development environment (installs dependencies and pre-commit hooks)
|
249
|
+
make dev-setup
|
250
|
+
```
|
251
|
+
|
252
|
+
### Code Quality Tools
|
253
|
+
|
254
|
+
This project uses modern Python tooling for code quality:
|
255
|
+
|
256
|
+
- **Ruff**: Fast Python linter and formatter (replaces Black + isort + flake8)
|
257
|
+
- **MyPy**: Static type checking for type safety
|
258
|
+
- **Pre-commit**: Git hooks for automated code quality checks
|
259
|
+
- **Poetry**: Modern dependency management and packaging
|
260
|
+
|
261
|
+
```bash
|
262
|
+
# Format code
|
263
|
+
make format
|
264
|
+
|
265
|
+
# Lint code
|
266
|
+
make lint
|
267
|
+
|
268
|
+
# Fix linting issues
|
269
|
+
make fix
|
270
|
+
|
271
|
+
# Run all checks (lint + type check)
|
272
|
+
make check
|
273
|
+
|
274
|
+
# Install pre-commit hooks
|
275
|
+
make install-hooks
|
276
|
+
|
277
|
+
# Run pre-commit hooks manually
|
278
|
+
make pre-commit
|
279
|
+
```
|
280
|
+
|
281
|
+
### Testing
|
282
|
+
|
283
|
+
```bash
|
284
|
+
# Set environment variables for integration tests
|
285
|
+
export DOMAIN="https://api.dify.ai"
|
286
|
+
export CHAT_KEY="your-chat-api-key"
|
287
|
+
export CHATFLOW_KEY="your-chatflow-api-key"
|
288
|
+
export COMPLETION_KEY="your-completion-api-key"
|
289
|
+
export DIFY_KEY="your-dify-api-key"
|
290
|
+
export WORKFLOW_KEY="your-workflow-api-key"
|
291
|
+
export KNOWLEDGE_KEY="your-knowledge-api-key"
|
292
|
+
|
293
|
+
# Run tests
|
294
|
+
make test
|
295
|
+
|
296
|
+
# Run tests with coverage
|
297
|
+
make test-cov
|
298
|
+
|
299
|
+
# Run specific test module
|
300
|
+
poetry run pytest tests/knowledge/ -v
|
301
|
+
```
|
302
|
+
|
303
|
+
### Build & Publish
|
304
|
+
|
305
|
+
```bash
|
306
|
+
# Configure PyPI tokens (one-time setup)
|
307
|
+
poetry config http-basic.testpypi __token__ <your-testpypi-token>
|
308
|
+
poetry config http-basic.pypi __token__ <your-pypi-token>
|
309
|
+
|
310
|
+
# Build package
|
311
|
+
make build
|
312
|
+
|
313
|
+
# Publish to TestPyPI (for testing)
|
314
|
+
make publish-test
|
315
|
+
|
316
|
+
# Publish to PyPI (maintainers only)
|
317
|
+
make publish
|
318
|
+
```
|
319
|
+
|
320
|
+
### Project Structure
|
321
|
+
|
322
|
+
```
|
323
|
+
dify-oapi2/
|
324
|
+
├── dify_oapi/ # Main SDK package
|
325
|
+
│ ├── api/ # API service modules
|
326
|
+
│ │ ├── chat/ # Chat API (18 APIs)
|
327
|
+
│ │ │ └── v1/ # Version 1 implementation
|
328
|
+
│ │ ├── chatflow/ # Chatflow API (15 APIs)
|
329
|
+
│ │ │ └── v1/ # Version 1 implementation
|
330
|
+
│ │ ├── completion/ # Completion API (10 APIs)
|
331
|
+
│ │ │ └── v1/ # Version 1 implementation
|
332
|
+
│ │ ├── dify/ # Core Dify API (9 APIs)
|
333
|
+
│ │ │ └── v1/ # Version 1 implementation
|
334
|
+
│ │ ├── knowledge/ # Knowledge Base API (33 APIs)
|
335
|
+
│ │ │ └── v1/ # Version 1 implementation
|
336
|
+
│ │ └── workflow/ # Workflow API (6 APIs)
|
337
|
+
│ │ └── v1/ # Version 1 implementation
|
338
|
+
│ ├── core/ # Core functionality
|
339
|
+
│ │ ├── http/ # HTTP transport layer with connection pooling
|
340
|
+
│ │ ├── model/ # Base models and configurations
|
341
|
+
│ │ └── utils/ # Utility functions
|
342
|
+
│ └── client.py # Main client interface with builder pattern
|
343
|
+
├── docs/ # Comprehensive documentation
|
344
|
+
├── examples/ # Complete usage examples for all APIs
|
345
|
+
├── tests/ # Comprehensive test suite
|
346
|
+
├── pyproject.toml # Project configuration (Poetry + tools)
|
347
|
+
├── Makefile # Development automation
|
348
|
+
└── DEVELOPMENT.md # Development guide
|
349
|
+
```
|
350
|
+
|
351
|
+
## 📖 Documentation
|
352
|
+
|
353
|
+
- [**Development Guide**](./DEVELOPMENT.md) - Setup, workflow, and contribution guidelines
|
354
|
+
- [**Project Overview**](./docs/overview.md) - Architecture and technical details
|
355
|
+
- [**API Documentation**](./docs/) - Complete API documentation by service
|
356
|
+
- [**Examples**](./examples/README.md) - Comprehensive usage examples and patterns
|
357
|
+
|
358
|
+
## 🤝 Contributing
|
359
|
+
|
360
|
+
Contributions are welcome! Please follow our development workflow:
|
361
|
+
|
362
|
+
1. Fork the repository
|
363
|
+
2. Clone and checkout the `main` branch (`git checkout main`)
|
364
|
+
3. Create a feature branch from `main` (`git checkout -b feature/amazing-feature`)
|
365
|
+
4. Make your changes with comprehensive tests
|
366
|
+
5. Ensure code quality passes (`make check`)
|
367
|
+
6. Run the full test suite (`make test`)
|
368
|
+
7. Commit your changes (`git commit -m 'Add amazing feature'`)
|
369
|
+
8. Push to the branch (`git push origin feature/amazing-feature`)
|
370
|
+
9. Submit a pull request to the `main` branch
|
371
|
+
|
372
|
+
### Branch Strategy
|
373
|
+
|
374
|
+
- `main` - Main development branch, **all development and PRs are based on this branch**
|
375
|
+
- `feature/*` - Feature branches, created from and merged back to `main`
|
376
|
+
- `bugfix/*` - Bug fix branches, created from and merged back to `main`
|
377
|
+
- `hotfix/*` - Urgent fixes, created from and merged back to `main`
|
378
|
+
|
379
|
+
See [DEVELOPMENT.md](./DEVELOPMENT.md) for detailed development guidelines.
|
380
|
+
|
381
|
+
## 📄 License
|
382
|
+
|
383
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
384
|
+
|
385
|
+
## 🔗 Links
|
386
|
+
|
387
|
+
- **PyPI Package**: https://pypi.org/project/dify-oapi2/
|
388
|
+
- **Source Code**: https://github.com/nodite/dify-oapi2
|
389
|
+
- **Dify Platform**: https://dify.ai/
|
390
|
+
- **Dify API Docs**: https://docs.dify.ai/
|
391
|
+
|
392
|
+
---
|
393
|
+
|
394
|
+
**Keywords**: dify, ai, nlp, language-processing, python-sdk, async, type-safe, api-client
|
395
|
+
|
@@ -396,7 +396,7 @@ dify_oapi/core/model/request_option.py,sha256=JWJ04FBIu-AwSMVSJC-U1QLF0b3PzKyHyU
|
|
396
396
|
dify_oapi/core/type.py,sha256=XYa5Z_kEq4Q1YcCKiN6KooMt9OlLewT4wnJm-fhRsok,126
|
397
397
|
dify_oapi/core/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
398
398
|
dify_oapi/core/utils/strings.py,sha256=pVnu8iBLkMUb_7iOWYLl7RKSPe_J2GdA2rgCkh3VQec,217
|
399
|
-
dify_oapi2-1.0.
|
400
|
-
dify_oapi2-1.0.
|
401
|
-
dify_oapi2-1.0.
|
402
|
-
dify_oapi2-1.0.
|
399
|
+
dify_oapi2-1.0.2.dist-info/METADATA,sha256=ivb3mu-bCh1sISUJvJoHDOCEcyNxeAc0dcMkie-aqdQ,15025
|
400
|
+
dify_oapi2-1.0.2.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
401
|
+
dify_oapi2-1.0.2.dist-info/licenses/LICENSE,sha256=-5M97mtDVKhlrPNcbmlktonQVEdD3M2FOaffN_1hgZk,1067
|
402
|
+
dify_oapi2-1.0.2.dist-info/RECORD,,
|
@@ -1,367 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: dify-oapi2
|
3
|
-
Version: 1.0.1
|
4
|
-
Summary: A package for interacting with the Dify Service-API
|
5
|
-
License: MIT
|
6
|
-
License-File: LICENSE
|
7
|
-
Keywords: dify,nlp,ai,language-processing
|
8
|
-
Author: Oscaner Miao
|
9
|
-
Author-email: oscaner1997@gmail.com
|
10
|
-
Requires-Python: >=3.10
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
17
|
-
Classifier: Programming Language :: Python :: 3.14
|
18
|
-
Requires-Dist: httpx (>=0,<1)
|
19
|
-
Requires-Dist: pydantic (>=2,<3)
|
20
|
-
Project-URL: Homepage, https://github.com/nodite/dify-oapi2
|
21
|
-
Project-URL: Source, https://github.com/nodite/dify-oapi2
|
22
|
-
Description-Content-Type: text/markdown
|
23
|
-
|
24
|
-
# Dify-OAPI
|
25
|
-
|
26
|
-
[](https://badge.fury.io/py/dify-oapi2)
|
27
|
-
[](https://www.python.org/downloads/)
|
28
|
-
[](https://opensource.org/licenses/MIT)
|
29
|
-
|
30
|
-
A modern Python SDK for interacting with the Dify Service-API. This library provides a fluent, type-safe interface for building AI-powered applications using Dify's comprehensive API services including chat, completion, knowledge base, workflow, and chatflow features.
|
31
|
-
|
32
|
-
> This project is based on https://github.com/QiMington/dify-oapi, completely refactored with modern Python practices and full support for the latest Dify API.
|
33
|
-
|
34
|
-
## ✨ Features
|
35
|
-
|
36
|
-
- **Complete API Coverage**: Chat (18 APIs), Chatflow (15 APIs), Completion (10 APIs), Knowledge Base (33 APIs), Workflow (4 APIs), and Core Dify (9 APIs)
|
37
|
-
- **Builder Pattern**: Fluent, chainable interface for constructing requests
|
38
|
-
- **Sync & Async Support**: Both synchronous and asynchronous operations
|
39
|
-
- **Streaming Responses**: Real-time streaming for chat and completion
|
40
|
-
- **Type Safety**: Comprehensive type hints with Pydantic 2.x validation
|
41
|
-
- **File Upload**: Support for images and documents
|
42
|
-
- **Modern HTTP Client**: Built on httpx for reliable API communication
|
43
|
-
- **Connection Pool Optimization**: Efficient TCP connection reuse to reduce resource overhead
|
44
|
-
|
45
|
-
## 📦 Installation
|
46
|
-
|
47
|
-
```bash
|
48
|
-
pip install dify-oapi2
|
49
|
-
```
|
50
|
-
|
51
|
-
**Requirements**: Python 3.10+
|
52
|
-
|
53
|
-
**Core Dependencies**:
|
54
|
-
- `pydantic` (^2) - Data validation and settings management with type safety
|
55
|
-
- `httpx` (^0) - Modern async HTTP client
|
56
|
-
|
57
|
-
**Development Dependencies**:
|
58
|
-
- `ruff` (^0) - Fast Python linter and formatter
|
59
|
-
- `mypy` (^1) - Static type checking
|
60
|
-
- `pytest` (^8) - Testing framework
|
61
|
-
- `pre-commit` (^4) - Git hooks for code quality
|
62
|
-
- `commitizen` (^4) - Semantic versioning and changelog generation
|
63
|
-
- `poetry` - Dependency management and packaging
|
64
|
-
|
65
|
-
## 🛠️ Technology Stack
|
66
|
-
|
67
|
-
- **Language**: Python 3.10+
|
68
|
-
- **HTTP Client**: httpx with connection pooling optimization
|
69
|
-
- **Type System**: Pydantic 2.x with comprehensive type validation
|
70
|
-
- **Architecture**: Builder pattern with fluent API design + Service layer pattern
|
71
|
-
- **Async Support**: Full async/await support with AsyncGenerator streaming
|
72
|
-
- **Code Quality**: Ruff (linting + formatting) + MyPy (type checking)
|
73
|
-
- **Testing**: pytest with async support and comprehensive coverage
|
74
|
-
- **Packaging**: Poetry with modern Python packaging standards
|
75
|
-
- **Total Coverage**: 89 API methods across 6 services with complete examples
|
76
|
-
|
77
|
-
## 🚀 Quick Start
|
78
|
-
|
79
|
-
### Basic Usage
|
80
|
-
|
81
|
-
```python
|
82
|
-
from dify_oapi.client import Client
|
83
|
-
from dify_oapi.core.model.request_option import RequestOption
|
84
|
-
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
|
85
|
-
|
86
|
-
# Initialize client with builder pattern
|
87
|
-
client = (
|
88
|
-
Client.builder()
|
89
|
-
.domain("https://api.dify.ai")
|
90
|
-
.max_connections(100)
|
91
|
-
.keepalive_expiry(30.0)
|
92
|
-
.build()
|
93
|
-
)
|
94
|
-
|
95
|
-
# Create request options
|
96
|
-
req_option = RequestOption.builder().api_key("your-api-key").build()
|
97
|
-
|
98
|
-
# Use the chat API
|
99
|
-
response = client.chat.chat(
|
100
|
-
request=ChatRequest.builder()
|
101
|
-
.query("Hello, how are you?")
|
102
|
-
.user("user-123")
|
103
|
-
.build(),
|
104
|
-
request_option=req_option
|
105
|
-
)
|
106
|
-
|
107
|
-
print(response.answer)
|
108
|
-
```
|
109
|
-
|
110
|
-
### Comprehensive Examples
|
111
|
-
|
112
|
-
Ready to build AI-powered applications? Check out our comprehensive examples:
|
113
|
-
|
114
|
-
- **[Chat Examples](./examples/chat/)** - Interactive conversations and streaming responses
|
115
|
-
- **[Chatflow Examples](./examples/chatflow/)** - Enhanced chat with workflow events
|
116
|
-
- **[Knowledge Base Examples](./examples/knowledge/)** - Build and query knowledge bases
|
117
|
-
- **[Workflow Examples](./examples/workflow/)** - Automate complex AI workflows
|
118
|
-
- **[Complete Examples Collection](./examples/)** - All API services with detailed usage patterns
|
119
|
-
|
120
|
-
Each example includes complete, runnable code with detailed explanations.
|
121
|
-
|
122
|
-
## 🔧 API Services
|
123
|
-
|
124
|
-
### Chat API (18 APIs)
|
125
|
-
**Resources**: annotation (6), chat (3), conversation (6), message (3)
|
126
|
-
- **Interactive Chat**: Send messages with blocking/streaming responses
|
127
|
-
- **Conversation Management**: Complete conversation lifecycle operations
|
128
|
-
- **Annotation System**: Create, update, delete annotations with reply settings
|
129
|
-
- **Message Operations**: Basic message handling and history retrieval
|
130
|
-
- **Streaming Support**: Real-time streaming for chat responses
|
131
|
-
- **Type Safety**: Comprehensive type hints with strict Literal types
|
132
|
-
|
133
|
-
### Chatflow API (15 APIs)
|
134
|
-
**Resources**: annotation (6), chatflow (3), conversation (6)
|
135
|
-
- **Enhanced Chat**: Advanced chat functionality with workflow events
|
136
|
-
- **Conversation Management**: Complete conversation operations with variables
|
137
|
-
- **Annotation System**: Full annotation management and reply configuration
|
138
|
-
- **Workflow Integration**: Seamless integration with workflow events
|
139
|
-
- **Event Streaming**: Real-time streaming with comprehensive event handling
|
140
|
-
- **Type Safety**: Strict Literal types for all predefined values
|
141
|
-
|
142
|
-
### Completion API (10 APIs)
|
143
|
-
**Resources**: annotation (6), completion (4)
|
144
|
-
- **Text Generation**: Advanced text completion and generation
|
145
|
-
- **Message Processing**: Send messages and control text generation
|
146
|
-
- **Annotation Management**: Create, update, and manage annotations
|
147
|
-
- **Generation Control**: Stop ongoing text generation processes
|
148
|
-
- **Streaming Support**: Real-time text generation with streaming responses
|
149
|
-
- **Type Safety**: Full type validation with Pydantic models
|
150
|
-
|
151
|
-
### Knowledge Base API (33 APIs)
|
152
|
-
**Resources**: chunk (4), dataset (6), document (10), model (1), segment (5), tag (7)
|
153
|
-
- **Dataset Management**: Complete dataset CRUD operations and content retrieval
|
154
|
-
- **Document Processing**: File upload, text processing, and batch management
|
155
|
-
- **Content Organization**: Fine-grained segmentation and chunk management
|
156
|
-
- **Tag System**: Flexible tagging and categorization system
|
157
|
-
- **Model Integration**: Embedding model information and configuration
|
158
|
-
- **Search & Retrieval**: Advanced search with multiple retrieval strategies
|
159
|
-
|
160
|
-
### Workflow API (4 APIs)
|
161
|
-
**Resources**: workflow (4)
|
162
|
-
- **Workflow Execution**: Run workflows with blocking or streaming responses
|
163
|
-
- **Execution Control**: Stop running workflows and monitor progress
|
164
|
-
- **Log Management**: Retrieve detailed execution logs and run details
|
165
|
-
- **Parameter Support**: Flexible workflow parameter configuration
|
166
|
-
|
167
|
-
### Dify Core API (9 APIs)
|
168
|
-
**Resources**: audio (2), feedback (2), file (1), info (4)
|
169
|
-
- **Audio Processing**: Speech-to-text and text-to-speech conversion
|
170
|
-
- **Feedback System**: Submit and retrieve user feedback
|
171
|
-
- **File Management**: Unified file upload and processing
|
172
|
-
- **Application Info**: App configuration, parameters, and metadata access
|
173
|
-
|
174
|
-
## 💡 Examples
|
175
|
-
|
176
|
-
Explore comprehensive examples in the [examples directory](./examples):
|
177
|
-
|
178
|
-
### Chat Examples
|
179
|
-
- [**Chat Messages**](./examples/chat/chat/) - Send messages, stop generation, get suggestions
|
180
|
-
- [**Conversation Management**](./examples/chat/conversation/) - Complete conversation operations
|
181
|
-
- [**Message Operations**](./examples/chat/message/) - Basic message operations
|
182
|
-
- [**Annotation Management**](./examples/chat/annotation/) - Annotation CRUD and reply settings
|
183
|
-
|
184
|
-
*Note: File upload and feedback examples are available in [Dify Core API](./examples/dify/) as shared services.*
|
185
|
-
|
186
|
-
### Completion Examples
|
187
|
-
- [**Completion Operations**](./examples/completion/completion/) - Text generation and completion
|
188
|
-
- [**Annotation Management**](./examples/completion/annotation/) - Annotation operations
|
189
|
-
|
190
|
-
### Knowledge Base Examples
|
191
|
-
- [**Dataset Management**](./examples/knowledge/dataset/) - Complete dataset operations
|
192
|
-
- [**Document Processing**](./examples/knowledge/document/) - File upload and text processing
|
193
|
-
- [**Content Organization**](./examples/knowledge/segment/) - Segment and chunk management
|
194
|
-
- [**Tag Management**](./examples/knowledge/tag/) - Metadata and tagging system
|
195
|
-
|
196
|
-
### Chatflow Examples
|
197
|
-
- [**Advanced Chat**](./examples/chatflow/chatflow/) - Enhanced chat with streaming and workflow events
|
198
|
-
- [**Conversation Management**](./examples/chatflow/conversation/) - Complete conversation operations
|
199
|
-
- [**Annotation Management**](./examples/chatflow/annotation/) - Annotation CRUD and reply settings
|
200
|
-
|
201
|
-
### Dify Core Examples
|
202
|
-
- [**Audio Processing**](./examples/dify/audio/) - Speech-to-text and text-to-speech
|
203
|
-
- [**Feedback Management**](./examples/dify/feedback/) - User feedback collection
|
204
|
-
- [**File Management**](./examples/dify/file/) - File upload and processing
|
205
|
-
- [**Application Info**](./examples/dify/info/) - App configuration and metadata
|
206
|
-
|
207
|
-
### Workflow Examples
|
208
|
-
- [**Workflow Operations**](./examples/workflow/workflow/) - Workflow execution and management
|
209
|
-
- [**File Upload**](./examples/workflow/file/) - File upload for workflows
|
210
|
-
|
211
|
-
For detailed examples and usage patterns, see the [examples README](./examples/README.md).
|
212
|
-
|
213
|
-
## 🛠️ Development
|
214
|
-
|
215
|
-
### Prerequisites
|
216
|
-
- Python 3.10+
|
217
|
-
- Poetry (for dependency management)
|
218
|
-
- Git (for version control)
|
219
|
-
|
220
|
-
### Setup
|
221
|
-
|
222
|
-
```bash
|
223
|
-
# Clone repository
|
224
|
-
git clone https://github.com/nodite/dify-oapi2.git
|
225
|
-
cd dify-oapi2
|
226
|
-
|
227
|
-
# Setup development environment (installs dependencies and pre-commit hooks)
|
228
|
-
make dev-setup
|
229
|
-
```
|
230
|
-
|
231
|
-
### Code Quality Tools
|
232
|
-
|
233
|
-
This project uses modern Python tooling for code quality:
|
234
|
-
|
235
|
-
- **Ruff**: Fast Python linter and formatter (replaces Black + isort + flake8)
|
236
|
-
- **MyPy**: Static type checking for type safety
|
237
|
-
- **Pre-commit**: Git hooks for automated code quality checks
|
238
|
-
- **Poetry**: Modern dependency management and packaging
|
239
|
-
|
240
|
-
```bash
|
241
|
-
# Format code
|
242
|
-
make format
|
243
|
-
|
244
|
-
# Lint code
|
245
|
-
make lint
|
246
|
-
|
247
|
-
# Fix linting issues
|
248
|
-
make fix
|
249
|
-
|
250
|
-
# Run all checks (lint + type check)
|
251
|
-
make check
|
252
|
-
|
253
|
-
# Install pre-commit hooks
|
254
|
-
make install-hooks
|
255
|
-
|
256
|
-
# Run pre-commit hooks manually
|
257
|
-
make pre-commit
|
258
|
-
```
|
259
|
-
|
260
|
-
### Testing
|
261
|
-
|
262
|
-
```bash
|
263
|
-
# Set environment variables for integration tests
|
264
|
-
export DOMAIN="https://api.dify.ai"
|
265
|
-
export CHAT_KEY="your-chat-api-key"
|
266
|
-
export CHATFLOW_KEY="your-chatflow-api-key"
|
267
|
-
export COMPLETION_KEY="your-completion-api-key"
|
268
|
-
export DIFY_KEY="your-dify-api-key"
|
269
|
-
export WORKFLOW_KEY="your-workflow-api-key"
|
270
|
-
export KNOWLEDGE_KEY="your-knowledge-api-key"
|
271
|
-
|
272
|
-
# Run tests
|
273
|
-
make test
|
274
|
-
|
275
|
-
# Run tests with coverage
|
276
|
-
make test-cov
|
277
|
-
|
278
|
-
# Run specific test module
|
279
|
-
poetry run pytest tests/knowledge/ -v
|
280
|
-
```
|
281
|
-
|
282
|
-
### Build & Publish
|
283
|
-
|
284
|
-
```bash
|
285
|
-
# Configure PyPI tokens (one-time setup)
|
286
|
-
poetry config http-basic.testpypi __token__ <your-testpypi-token>
|
287
|
-
poetry config http-basic.pypi __token__ <your-pypi-token>
|
288
|
-
|
289
|
-
# Build package
|
290
|
-
make build
|
291
|
-
|
292
|
-
# Publish to TestPyPI (for testing)
|
293
|
-
make publish-test
|
294
|
-
|
295
|
-
# Publish to PyPI (maintainers only)
|
296
|
-
make publish
|
297
|
-
```
|
298
|
-
|
299
|
-
### Project Structure
|
300
|
-
|
301
|
-
```
|
302
|
-
dify-oapi2/
|
303
|
-
├── dify_oapi/ # Main SDK package
|
304
|
-
│ ├── api/ # API service modules
|
305
|
-
│ │ ├── chat/ # Chat API (18 APIs)
|
306
|
-
│ │ │ └── v1/ # Version 1 implementation
|
307
|
-
│ │ ├── chatflow/ # Chatflow API (15 APIs)
|
308
|
-
│ │ │ └── v1/ # Version 1 implementation
|
309
|
-
│ │ ├── completion/ # Completion API (10 APIs)
|
310
|
-
│ │ │ └── v1/ # Version 1 implementation
|
311
|
-
│ │ ├── dify/ # Core Dify API (9 APIs)
|
312
|
-
│ │ │ └── v1/ # Version 1 implementation
|
313
|
-
│ │ ├── knowledge/ # Knowledge Base API (33 APIs)
|
314
|
-
│ │ │ └── v1/ # Version 1 implementation
|
315
|
-
│ │ └── workflow/ # Workflow API (6 APIs)
|
316
|
-
│ │ └── v1/ # Version 1 implementation
|
317
|
-
│ ├── core/ # Core functionality
|
318
|
-
│ │ ├── http/ # HTTP transport layer with connection pooling
|
319
|
-
│ │ ├── model/ # Base models and configurations
|
320
|
-
│ │ └── utils/ # Utility functions
|
321
|
-
│ └── client.py # Main client interface with builder pattern
|
322
|
-
├── docs/ # Comprehensive documentation
|
323
|
-
├── examples/ # Complete usage examples for all APIs
|
324
|
-
├── tests/ # Comprehensive test suite
|
325
|
-
├── pyproject.toml # Project configuration (Poetry + tools)
|
326
|
-
├── Makefile # Development automation
|
327
|
-
└── DEVELOPMENT.md # Development guide
|
328
|
-
```
|
329
|
-
|
330
|
-
## 📖 Documentation
|
331
|
-
|
332
|
-
- [**Development Guide**](./DEVELOPMENT.md) - Setup, workflow, and contribution guidelines
|
333
|
-
- [**Project Overview**](./docs/overview.md) - Architecture and technical details
|
334
|
-
- [**API Documentation**](./docs/) - Complete API documentation by service
|
335
|
-
- [**Examples**](./examples/README.md) - Comprehensive usage examples and patterns
|
336
|
-
|
337
|
-
|
338
|
-
## 🤝 Contributing
|
339
|
-
|
340
|
-
Contributions are welcome! Please follow our development workflow:
|
341
|
-
|
342
|
-
1. Fork the repository
|
343
|
-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
344
|
-
3. Make your changes with comprehensive tests
|
345
|
-
4. Ensure code quality passes (`make check`)
|
346
|
-
5. Run the full test suite (`make test`)
|
347
|
-
6. Commit your changes (`git commit -m 'Add amazing feature'`)
|
348
|
-
7. Push to the branch (`git push origin feature/amazing-feature`)
|
349
|
-
8. Submit a pull request
|
350
|
-
|
351
|
-
See [DEVELOPMENT.md](./DEVELOPMENT.md) for detailed development guidelines.
|
352
|
-
|
353
|
-
## 📄 License
|
354
|
-
|
355
|
-
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
356
|
-
|
357
|
-
## 🔗 Links
|
358
|
-
|
359
|
-
- **PyPI Package**: https://pypi.org/project/dify-oapi2/
|
360
|
-
- **Source Code**: https://github.com/nodite/dify-oapi2
|
361
|
-
- **Dify Platform**: https://dify.ai/
|
362
|
-
- **Dify API Docs**: https://docs.dify.ai/
|
363
|
-
|
364
|
-
---
|
365
|
-
|
366
|
-
**Keywords**: dify, ai, nlp, language-processing, python-sdk, async, type-safe, api-client
|
367
|
-
|
File without changes
|
File without changes
|