docges-api-py 0.1.4__tar.gz → 0.1.5__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.
Files changed (33) hide show
  1. docges_api_py-0.1.5/PKG-INFO +223 -0
  2. docges_api_py-0.1.5/README.md +203 -0
  3. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/pyproject.toml +1 -1
  4. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/client.py +7 -4
  5. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/models/responses.py +3 -0
  6. docges_api_py-0.1.5/src/docges_api_py.egg-info/PKG-INFO +223 -0
  7. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_examples.py +45 -28
  8. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_models_requests.py +2 -1
  9. docges_api_py-0.1.4/PKG-INFO +0 -161
  10. docges_api_py-0.1.4/README.md +0 -141
  11. docges_api_py-0.1.4/src/docges_api_py.egg-info/PKG-INFO +0 -161
  12. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/LICENSE +0 -0
  13. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/setup.cfg +0 -0
  14. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/__init__.py +0 -0
  15. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/models/__init__.py +0 -0
  16. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/models/auth.py +0 -0
  17. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/models/document.py +0 -0
  18. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py/models/requests.py +0 -0
  19. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py.egg-info/SOURCES.txt +0 -0
  20. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py.egg-info/dependency_links.txt +0 -0
  21. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py.egg-info/requires.txt +0 -0
  22. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/src/docges_api_py.egg-info/top_level.txt +0 -0
  23. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_client_auth.py +0 -0
  24. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_content_methods.py +0 -0
  25. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_endpoints.py +0 -0
  26. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_get_document.py +0 -0
  27. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_initial_cats.py +0 -0
  28. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_models_auth.py +0 -0
  29. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_models_init.py +0 -0
  30. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_models_responses.py +0 -0
  31. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_remaining_methods.py +0 -0
  32. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_retry.py +0 -0
  33. {docges_api_py-0.1.4 → docges_api_py-0.1.5}/tests/test_token_refresh.py +0 -0
@@ -0,0 +1,223 @@
1
+ Metadata-Version: 2.4
2
+ Name: docges-api-py
3
+ Version: 0.1.5
4
+ Summary: Async, typed Python client for DocGes REST API
5
+ Author-email: "ct.galega" <soporte@ctgalega.com>
6
+ License: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: httpx>=0.27
11
+ Requires-Dist: pydantic>=2.0
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest>=8.0; extra == "dev"
14
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
15
+ Requires-Dist: respx>=0.22; extra == "dev"
16
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
17
+ Requires-Dist: ruff>=0.4; extra == "dev"
18
+ Requires-Dist: mypy>=1.10; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # docges-api-py
22
+
23
+ Async, typed Python client for the DocGes REST API bridge (`docges-ctg-api`).
24
+
25
+ > **Production-ready** — bootstrapped via SDD (Spec-Driven Development).
26
+ > All core endpoints implemented with full test coverage (pytest + respx).
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install docges-api-py
32
+ ```
33
+
34
+ For development with testing tools:
35
+
36
+ ```bash
37
+ pip install -e ".[dev]"
38
+ ```
39
+
40
+ ## Features
41
+
42
+ - ✅ Async HTTP client using `httpx`
43
+ - ✅ Typed request/response models with Pydantic v2
44
+ - ✅ Configurable retries (exponential backoff) and timeouts
45
+ - ✅ Session-based auth: stores `loginResponse` from `/Auth/Login` and auto-injects it
46
+ for all Content endpoints
47
+ - ✅ Full test coverage (pytest + respx)
48
+ - ✅ Complete DocGes API client: categories, documents, search, CRUD operations
49
+
50
+ ## Implemented endpoints
51
+
52
+ ### Auth
53
+ | Method | Endpoint | Description |
54
+ |--------|----------|-------------|
55
+ | `auth()` | `POST /Auth/Login` | Authenticate and store session |
56
+
57
+ ### Content Tree
58
+ | Method | Endpoint | Description |
59
+ |--------|----------|-------------|
60
+ | `get_initial_cats()` | `POST /Content/LoadIniCats` | Load root categories for user's warehouse |
61
+ | `get_cat_info(sid)` | `POST /Content/LoadChilds` | Load subcategories and documents for a given category SID |
62
+
63
+ ### Document Operations
64
+ | Method | Endpoint | Description |
65
+ |--------|----------|-------------|
66
+ | `upload_file(category_sid, file_path)` | `POST /Content/UploadExtended` | Upload a file to a category |
67
+ | `download_content(sid)` | `POST /Content/Download` | Download a document (returns base64 data) |
68
+ | `get_document(sid)` | — | Deprecated wrapper for `download_content()` |
69
+
70
+ ### Search
71
+ | Method | Endpoint | Description |
72
+ |--------|----------|-------------|
73
+ | `search_content(field_values, date_values)` | `POST /Content/SearchContent` | Search documents by field or date criteria |
74
+
75
+ ### Category Management
76
+ | Method | Endpoint | Description |
77
+ |--------|----------|-------------|
78
+ | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
79
+ | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
80
+ | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
81
+
82
+ ### Document Management
83
+ | Method | Endpoint | Description |
84
+ |--------|----------|-------------|
85
+ | `remove_document(sid)` | `POST /Content/RemoveDocument` | Remove a single document |
86
+ | `move_content(content_sid, destination_sid)` | `POST /Content/Move` | Move a document to another category |
87
+ | `update_content(sid, erp_relation, erp_property)` | `POST /Content/Update` | Update document ERP metadata |
88
+
89
+ ## Quick start
90
+
91
+ ```bash
92
+ pip install -e ".[dev]"
93
+ ```
94
+
95
+ ```python
96
+ import asyncio
97
+ import os
98
+ from docges_api_py import AsyncDocGes
99
+
100
+ async def main():
101
+ base_url = os.getenv("DOCGES_API_BASE_URL")
102
+ user = os.getenv("DOCGES_USER")
103
+ pwd = os.getenv("DOCGES_PASSWORD")
104
+ appid = os.getenv("DOCGES_APP_ID")
105
+
106
+ async with AsyncDocGes(base_url, user, pwd, appid) as client:
107
+ auth_resp = await client.auth()
108
+ print(f"User: {auth_resp.user_info['Nombre']}")
109
+
110
+ # Browse root categories
111
+ cats = await client.get_initial_cats()
112
+ for cat in cats.CategoriasHijas or []:
113
+ print(f" {cat.Nombre} [SID: {cat.SID}]")
114
+
115
+ # Search documents
116
+ results = await client.search_content(
117
+ field_values=[{"field": "name", "mode": "contains", "text": "factura"}]
118
+ )
119
+ print(f"Search results: {len(results.results)}")
120
+
121
+ asyncio.run(main())
122
+ ```
123
+
124
+ ### Environment variables
125
+
126
+ | Variable | Description | Example |
127
+ |----------|-------------|---------|
128
+ | `DOCGES_API_BASE_URL` | Bridge base URL | `http://192.168.0.90:49375` |
129
+ | `DOCGES_USER` | Username | `administrador` |
130
+ | `DOCGES_PASSWORD` | Password | `12345` |
131
+ | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
132
+
133
+ **Known appIDs and their servers:**
134
+ - `local-dev` — `192.168.0.90:49375/Almacen1`
135
+ - `pre-dev` — `apps.ctgalega.com:54433/devbg`
136
+
137
+ ## Examples
138
+
139
+ All examples read credentials from environment variables. Run them with:
140
+
141
+ ```bash
142
+ export DOCGES_API_BASE_URL=http://192.168.0.90:49375
143
+ export DOCGES_USER=administrador
144
+ export DOCGES_PASSWORD=12345
145
+ export DOCGES_APP_ID=local-dev
146
+ python examples/<number>_<name>.py
147
+ ```
148
+
149
+ | # | File | What it does |
150
+ |---|------|-------------|
151
+ | 01 | `examples/01_auth.py` | Login and inspect session context |
152
+ | 02 | `examples/02_initial_cats.py` | Load and list root categories |
153
+ | 03 | `examples/03_browse_category.py` | Browse a category by SID (subcats + docs) |
154
+ | 04 | `examples/04_search.py` | Search documents by name |
155
+ | 05 | `examples/05_upload.py` | Upload a file to a category |
156
+ | 06 | `examples/06_download.py` | Download a document by SID |
157
+ | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
158
+ | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
159
+
160
+ ## Development
161
+
162
+ ```bash
163
+ pip install -e ".[dev]"
164
+ ruff check src/ tests/
165
+ mypy src/
166
+ pytest --cov=docges_api_py
167
+ ```
168
+
169
+ ## Architecture notes
170
+
171
+ - The DocGes REST API is a thin bridge in front of DocGes WCF services. It uses session-based auth: `/Auth/Login` returns a `loginResponse` (containing `userInfo` and `wareHouseInfo`) that must be passed back on every Content request via `requestModel.loginResponse`.
172
+ - Content endpoints expect `contenidoModel`, `fileModel`, etc. as **top-level fields** alongside `requestModel`, not nested inside it. The client builds the correct payload shape automatically.
173
+ - For DocGes Web (bridge) compatibility, the client also includes `loginDocGesData` (username/password/appID) in `requestModel` — this is needed by some bridge deployments that reconstruct the DocGes login model server-side.
174
+ - All file content is base64-encoded in transit (handled automatically by the client).
175
+
176
+ ## Project structure
177
+
178
+ ```
179
+ docges-api-py/
180
+ ├── src/docges_api_py/
181
+ │ ├── __init__.py # Exports AsyncDocGes, models
182
+ │ ├── client.py # AsyncDocGes client (all endpoints)
183
+ │ └── models/
184
+ │ ├── __init__.py # Re-exports all models
185
+ │ ├── auth.py # AuthRequest, AuthResponse
186
+ │ ├── document.py # Document
187
+ │ ├── requests.py # Request models (Pydantic v2)
188
+ │ └── responses.py # Response models (ResCat, ResFileDownload, etc.)
189
+ ├── tests/
190
+ │ ├── conftest.py
191
+ │ ├── test_client_auth.py
192
+ │ ├── test_initial_cats.py
193
+ │ ├── test_content_methods.py
194
+ │ ├── test_remaining_methods.py
195
+ │ ├── test_models_requests.py
196
+ │ ├── test_models_responses.py
197
+ │ ├── test_models_init.py
198
+ │ ├── test_endpoints.py
199
+ │ ├── test_retry.py
200
+ │ ├── test_token_refresh.py
201
+ │ └── test_examples.py
202
+ ├── examples/
203
+ │ ├── 01_auth.py
204
+ │ ├── 02_initial_cats.py
205
+ │ ├── 03_browse_category.py
206
+ │ ├── 04_search.py
207
+ │ ├── 05_upload.py
208
+ │ ├── 06_download.py
209
+ │ ├── 07_category_crud.py
210
+ │ └── 08_document_operations.py
211
+ ├── docs/
212
+ │ └── MIGRATION.md
213
+ ├── scripts/
214
+ │ └── docges_debug/ # Debug helpers for payload investigation
215
+ ├── pyproject.toml
216
+ ├── ruff.toml
217
+ ├── mypy.ini
218
+ └── README.md
219
+ ```
220
+
221
+ ## Contributing
222
+
223
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
@@ -0,0 +1,203 @@
1
+ # docges-api-py
2
+
3
+ Async, typed Python client for the DocGes REST API bridge (`docges-ctg-api`).
4
+
5
+ > **Production-ready** — bootstrapped via SDD (Spec-Driven Development).
6
+ > All core endpoints implemented with full test coverage (pytest + respx).
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install docges-api-py
12
+ ```
13
+
14
+ For development with testing tools:
15
+
16
+ ```bash
17
+ pip install -e ".[dev]"
18
+ ```
19
+
20
+ ## Features
21
+
22
+ - ✅ Async HTTP client using `httpx`
23
+ - ✅ Typed request/response models with Pydantic v2
24
+ - ✅ Configurable retries (exponential backoff) and timeouts
25
+ - ✅ Session-based auth: stores `loginResponse` from `/Auth/Login` and auto-injects it
26
+ for all Content endpoints
27
+ - ✅ Full test coverage (pytest + respx)
28
+ - ✅ Complete DocGes API client: categories, documents, search, CRUD operations
29
+
30
+ ## Implemented endpoints
31
+
32
+ ### Auth
33
+ | Method | Endpoint | Description |
34
+ |--------|----------|-------------|
35
+ | `auth()` | `POST /Auth/Login` | Authenticate and store session |
36
+
37
+ ### Content Tree
38
+ | Method | Endpoint | Description |
39
+ |--------|----------|-------------|
40
+ | `get_initial_cats()` | `POST /Content/LoadIniCats` | Load root categories for user's warehouse |
41
+ | `get_cat_info(sid)` | `POST /Content/LoadChilds` | Load subcategories and documents for a given category SID |
42
+
43
+ ### Document Operations
44
+ | Method | Endpoint | Description |
45
+ |--------|----------|-------------|
46
+ | `upload_file(category_sid, file_path)` | `POST /Content/UploadExtended` | Upload a file to a category |
47
+ | `download_content(sid)` | `POST /Content/Download` | Download a document (returns base64 data) |
48
+ | `get_document(sid)` | — | Deprecated wrapper for `download_content()` |
49
+
50
+ ### Search
51
+ | Method | Endpoint | Description |
52
+ |--------|----------|-------------|
53
+ | `search_content(field_values, date_values)` | `POST /Content/SearchContent` | Search documents by field or date criteria |
54
+
55
+ ### Category Management
56
+ | Method | Endpoint | Description |
57
+ |--------|----------|-------------|
58
+ | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
59
+ | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
60
+ | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
61
+
62
+ ### Document Management
63
+ | Method | Endpoint | Description |
64
+ |--------|----------|-------------|
65
+ | `remove_document(sid)` | `POST /Content/RemoveDocument` | Remove a single document |
66
+ | `move_content(content_sid, destination_sid)` | `POST /Content/Move` | Move a document to another category |
67
+ | `update_content(sid, erp_relation, erp_property)` | `POST /Content/Update` | Update document ERP metadata |
68
+
69
+ ## Quick start
70
+
71
+ ```bash
72
+ pip install -e ".[dev]"
73
+ ```
74
+
75
+ ```python
76
+ import asyncio
77
+ import os
78
+ from docges_api_py import AsyncDocGes
79
+
80
+ async def main():
81
+ base_url = os.getenv("DOCGES_API_BASE_URL")
82
+ user = os.getenv("DOCGES_USER")
83
+ pwd = os.getenv("DOCGES_PASSWORD")
84
+ appid = os.getenv("DOCGES_APP_ID")
85
+
86
+ async with AsyncDocGes(base_url, user, pwd, appid) as client:
87
+ auth_resp = await client.auth()
88
+ print(f"User: {auth_resp.user_info['Nombre']}")
89
+
90
+ # Browse root categories
91
+ cats = await client.get_initial_cats()
92
+ for cat in cats.CategoriasHijas or []:
93
+ print(f" {cat.Nombre} [SID: {cat.SID}]")
94
+
95
+ # Search documents
96
+ results = await client.search_content(
97
+ field_values=[{"field": "name", "mode": "contains", "text": "factura"}]
98
+ )
99
+ print(f"Search results: {len(results.results)}")
100
+
101
+ asyncio.run(main())
102
+ ```
103
+
104
+ ### Environment variables
105
+
106
+ | Variable | Description | Example |
107
+ |----------|-------------|---------|
108
+ | `DOCGES_API_BASE_URL` | Bridge base URL | `http://192.168.0.90:49375` |
109
+ | `DOCGES_USER` | Username | `administrador` |
110
+ | `DOCGES_PASSWORD` | Password | `12345` |
111
+ | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
112
+
113
+ **Known appIDs and their servers:**
114
+ - `local-dev` — `192.168.0.90:49375/Almacen1`
115
+ - `pre-dev` — `apps.ctgalega.com:54433/devbg`
116
+
117
+ ## Examples
118
+
119
+ All examples read credentials from environment variables. Run them with:
120
+
121
+ ```bash
122
+ export DOCGES_API_BASE_URL=http://192.168.0.90:49375
123
+ export DOCGES_USER=administrador
124
+ export DOCGES_PASSWORD=12345
125
+ export DOCGES_APP_ID=local-dev
126
+ python examples/<number>_<name>.py
127
+ ```
128
+
129
+ | # | File | What it does |
130
+ |---|------|-------------|
131
+ | 01 | `examples/01_auth.py` | Login and inspect session context |
132
+ | 02 | `examples/02_initial_cats.py` | Load and list root categories |
133
+ | 03 | `examples/03_browse_category.py` | Browse a category by SID (subcats + docs) |
134
+ | 04 | `examples/04_search.py` | Search documents by name |
135
+ | 05 | `examples/05_upload.py` | Upload a file to a category |
136
+ | 06 | `examples/06_download.py` | Download a document by SID |
137
+ | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
138
+ | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
139
+
140
+ ## Development
141
+
142
+ ```bash
143
+ pip install -e ".[dev]"
144
+ ruff check src/ tests/
145
+ mypy src/
146
+ pytest --cov=docges_api_py
147
+ ```
148
+
149
+ ## Architecture notes
150
+
151
+ - The DocGes REST API is a thin bridge in front of DocGes WCF services. It uses session-based auth: `/Auth/Login` returns a `loginResponse` (containing `userInfo` and `wareHouseInfo`) that must be passed back on every Content request via `requestModel.loginResponse`.
152
+ - Content endpoints expect `contenidoModel`, `fileModel`, etc. as **top-level fields** alongside `requestModel`, not nested inside it. The client builds the correct payload shape automatically.
153
+ - For DocGes Web (bridge) compatibility, the client also includes `loginDocGesData` (username/password/appID) in `requestModel` — this is needed by some bridge deployments that reconstruct the DocGes login model server-side.
154
+ - All file content is base64-encoded in transit (handled automatically by the client).
155
+
156
+ ## Project structure
157
+
158
+ ```
159
+ docges-api-py/
160
+ ├── src/docges_api_py/
161
+ │ ├── __init__.py # Exports AsyncDocGes, models
162
+ │ ├── client.py # AsyncDocGes client (all endpoints)
163
+ │ └── models/
164
+ │ ├── __init__.py # Re-exports all models
165
+ │ ├── auth.py # AuthRequest, AuthResponse
166
+ │ ├── document.py # Document
167
+ │ ├── requests.py # Request models (Pydantic v2)
168
+ │ └── responses.py # Response models (ResCat, ResFileDownload, etc.)
169
+ ├── tests/
170
+ │ ├── conftest.py
171
+ │ ├── test_client_auth.py
172
+ │ ├── test_initial_cats.py
173
+ │ ├── test_content_methods.py
174
+ │ ├── test_remaining_methods.py
175
+ │ ├── test_models_requests.py
176
+ │ ├── test_models_responses.py
177
+ │ ├── test_models_init.py
178
+ │ ├── test_endpoints.py
179
+ │ ├── test_retry.py
180
+ │ ├── test_token_refresh.py
181
+ │ └── test_examples.py
182
+ ├── examples/
183
+ │ ├── 01_auth.py
184
+ │ ├── 02_initial_cats.py
185
+ │ ├── 03_browse_category.py
186
+ │ ├── 04_search.py
187
+ │ ├── 05_upload.py
188
+ │ ├── 06_download.py
189
+ │ ├── 07_category_crud.py
190
+ │ └── 08_document_operations.py
191
+ ├── docs/
192
+ │ └── MIGRATION.md
193
+ ├── scripts/
194
+ │ └── docges_debug/ # Debug helpers for payload investigation
195
+ ├── pyproject.toml
196
+ ├── ruff.toml
197
+ ├── mypy.ini
198
+ └── README.md
199
+ ```
200
+
201
+ ## Contributing
202
+
203
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "docges-api-py"
7
- version = "0.1.4"
7
+ version = "0.1.5"
8
8
  description = "Async, typed Python client for DocGes REST API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -142,9 +142,12 @@ class AsyncDocGes:
142
142
 
143
143
  # Normalize: copy SIDraiz to SID in wareHouseInfo for bridge compatibility
144
144
  # The bridge C# code expects wareHouseInfo.SID, but the API returns SIDraiz
145
- if "wareHouseInfo" in resp and "SIDraiz" in resp["wareHouseInfo"]:
146
- if "SID" not in resp["wareHouseInfo"]:
147
- resp["wareHouseInfo"]["SID"] = resp["wareHouseInfo"]["SIDraiz"]
145
+ if (
146
+ "wareHouseInfo" in resp
147
+ and "SIDraiz" in resp["wareHouseInfo"]
148
+ and "SID" not in resp["wareHouseInfo"]
149
+ ):
150
+ resp["wareHouseInfo"]["SID"] = resp["wareHouseInfo"]["SIDraiz"]
148
151
 
149
152
  # Store the normalized dict for injection into every subsequent /Content/* request
150
153
  self._login_response = resp
@@ -206,7 +209,7 @@ class AsyncDocGes:
206
209
  # Build final payload: extra data fields (contenidoModel, fileModel, etc.)
207
210
  # go at TOP LEVEL alongside requestModel — NOT nested inside requestModel.
208
211
  # This matches the server's RequestContentModel: { contenidoModel, requestModel }.
209
- payload: dict[str, Any] = {"requestModel": request_model}
212
+ payload = {"requestModel": request_model}
210
213
  if data is not None:
211
214
  extra = data.model_dump(exclude_none=True)
212
215
  # If data itself has a requestModel key, merge it into the top-level one
@@ -21,6 +21,9 @@ class ResCatItem(DocGesResponseModel):
21
21
 
22
22
  class ResCat(DocGesResponseModel):
23
23
  """Response from /Content/LoadIniCats and /Content/LoadChilds."""
24
+ Nombre: str | None = None
25
+ SID: str | None = None
26
+ CategoriaMadre: dict | None = None
24
27
  CategoriasHijas: list[dict] | None = None
25
28
  Documentos: list[dict] | None = None
26
29
 
@@ -0,0 +1,223 @@
1
+ Metadata-Version: 2.4
2
+ Name: docges-api-py
3
+ Version: 0.1.5
4
+ Summary: Async, typed Python client for DocGes REST API
5
+ Author-email: "ct.galega" <soporte@ctgalega.com>
6
+ License: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: httpx>=0.27
11
+ Requires-Dist: pydantic>=2.0
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest>=8.0; extra == "dev"
14
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
15
+ Requires-Dist: respx>=0.22; extra == "dev"
16
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
17
+ Requires-Dist: ruff>=0.4; extra == "dev"
18
+ Requires-Dist: mypy>=1.10; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # docges-api-py
22
+
23
+ Async, typed Python client for the DocGes REST API bridge (`docges-ctg-api`).
24
+
25
+ > **Production-ready** — bootstrapped via SDD (Spec-Driven Development).
26
+ > All core endpoints implemented with full test coverage (pytest + respx).
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install docges-api-py
32
+ ```
33
+
34
+ For development with testing tools:
35
+
36
+ ```bash
37
+ pip install -e ".[dev]"
38
+ ```
39
+
40
+ ## Features
41
+
42
+ - ✅ Async HTTP client using `httpx`
43
+ - ✅ Typed request/response models with Pydantic v2
44
+ - ✅ Configurable retries (exponential backoff) and timeouts
45
+ - ✅ Session-based auth: stores `loginResponse` from `/Auth/Login` and auto-injects it
46
+ for all Content endpoints
47
+ - ✅ Full test coverage (pytest + respx)
48
+ - ✅ Complete DocGes API client: categories, documents, search, CRUD operations
49
+
50
+ ## Implemented endpoints
51
+
52
+ ### Auth
53
+ | Method | Endpoint | Description |
54
+ |--------|----------|-------------|
55
+ | `auth()` | `POST /Auth/Login` | Authenticate and store session |
56
+
57
+ ### Content Tree
58
+ | Method | Endpoint | Description |
59
+ |--------|----------|-------------|
60
+ | `get_initial_cats()` | `POST /Content/LoadIniCats` | Load root categories for user's warehouse |
61
+ | `get_cat_info(sid)` | `POST /Content/LoadChilds` | Load subcategories and documents for a given category SID |
62
+
63
+ ### Document Operations
64
+ | Method | Endpoint | Description |
65
+ |--------|----------|-------------|
66
+ | `upload_file(category_sid, file_path)` | `POST /Content/UploadExtended` | Upload a file to a category |
67
+ | `download_content(sid)` | `POST /Content/Download` | Download a document (returns base64 data) |
68
+ | `get_document(sid)` | — | Deprecated wrapper for `download_content()` |
69
+
70
+ ### Search
71
+ | Method | Endpoint | Description |
72
+ |--------|----------|-------------|
73
+ | `search_content(field_values, date_values)` | `POST /Content/SearchContent` | Search documents by field or date criteria |
74
+
75
+ ### Category Management
76
+ | Method | Endpoint | Description |
77
+ |--------|----------|-------------|
78
+ | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
79
+ | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
80
+ | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
81
+
82
+ ### Document Management
83
+ | Method | Endpoint | Description |
84
+ |--------|----------|-------------|
85
+ | `remove_document(sid)` | `POST /Content/RemoveDocument` | Remove a single document |
86
+ | `move_content(content_sid, destination_sid)` | `POST /Content/Move` | Move a document to another category |
87
+ | `update_content(sid, erp_relation, erp_property)` | `POST /Content/Update` | Update document ERP metadata |
88
+
89
+ ## Quick start
90
+
91
+ ```bash
92
+ pip install -e ".[dev]"
93
+ ```
94
+
95
+ ```python
96
+ import asyncio
97
+ import os
98
+ from docges_api_py import AsyncDocGes
99
+
100
+ async def main():
101
+ base_url = os.getenv("DOCGES_API_BASE_URL")
102
+ user = os.getenv("DOCGES_USER")
103
+ pwd = os.getenv("DOCGES_PASSWORD")
104
+ appid = os.getenv("DOCGES_APP_ID")
105
+
106
+ async with AsyncDocGes(base_url, user, pwd, appid) as client:
107
+ auth_resp = await client.auth()
108
+ print(f"User: {auth_resp.user_info['Nombre']}")
109
+
110
+ # Browse root categories
111
+ cats = await client.get_initial_cats()
112
+ for cat in cats.CategoriasHijas or []:
113
+ print(f" {cat.Nombre} [SID: {cat.SID}]")
114
+
115
+ # Search documents
116
+ results = await client.search_content(
117
+ field_values=[{"field": "name", "mode": "contains", "text": "factura"}]
118
+ )
119
+ print(f"Search results: {len(results.results)}")
120
+
121
+ asyncio.run(main())
122
+ ```
123
+
124
+ ### Environment variables
125
+
126
+ | Variable | Description | Example |
127
+ |----------|-------------|---------|
128
+ | `DOCGES_API_BASE_URL` | Bridge base URL | `http://192.168.0.90:49375` |
129
+ | `DOCGES_USER` | Username | `administrador` |
130
+ | `DOCGES_PASSWORD` | Password | `12345` |
131
+ | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
132
+
133
+ **Known appIDs and their servers:**
134
+ - `local-dev` — `192.168.0.90:49375/Almacen1`
135
+ - `pre-dev` — `apps.ctgalega.com:54433/devbg`
136
+
137
+ ## Examples
138
+
139
+ All examples read credentials from environment variables. Run them with:
140
+
141
+ ```bash
142
+ export DOCGES_API_BASE_URL=http://192.168.0.90:49375
143
+ export DOCGES_USER=administrador
144
+ export DOCGES_PASSWORD=12345
145
+ export DOCGES_APP_ID=local-dev
146
+ python examples/<number>_<name>.py
147
+ ```
148
+
149
+ | # | File | What it does |
150
+ |---|------|-------------|
151
+ | 01 | `examples/01_auth.py` | Login and inspect session context |
152
+ | 02 | `examples/02_initial_cats.py` | Load and list root categories |
153
+ | 03 | `examples/03_browse_category.py` | Browse a category by SID (subcats + docs) |
154
+ | 04 | `examples/04_search.py` | Search documents by name |
155
+ | 05 | `examples/05_upload.py` | Upload a file to a category |
156
+ | 06 | `examples/06_download.py` | Download a document by SID |
157
+ | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
158
+ | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
159
+
160
+ ## Development
161
+
162
+ ```bash
163
+ pip install -e ".[dev]"
164
+ ruff check src/ tests/
165
+ mypy src/
166
+ pytest --cov=docges_api_py
167
+ ```
168
+
169
+ ## Architecture notes
170
+
171
+ - The DocGes REST API is a thin bridge in front of DocGes WCF services. It uses session-based auth: `/Auth/Login` returns a `loginResponse` (containing `userInfo` and `wareHouseInfo`) that must be passed back on every Content request via `requestModel.loginResponse`.
172
+ - Content endpoints expect `contenidoModel`, `fileModel`, etc. as **top-level fields** alongside `requestModel`, not nested inside it. The client builds the correct payload shape automatically.
173
+ - For DocGes Web (bridge) compatibility, the client also includes `loginDocGesData` (username/password/appID) in `requestModel` — this is needed by some bridge deployments that reconstruct the DocGes login model server-side.
174
+ - All file content is base64-encoded in transit (handled automatically by the client).
175
+
176
+ ## Project structure
177
+
178
+ ```
179
+ docges-api-py/
180
+ ├── src/docges_api_py/
181
+ │ ├── __init__.py # Exports AsyncDocGes, models
182
+ │ ├── client.py # AsyncDocGes client (all endpoints)
183
+ │ └── models/
184
+ │ ├── __init__.py # Re-exports all models
185
+ │ ├── auth.py # AuthRequest, AuthResponse
186
+ │ ├── document.py # Document
187
+ │ ├── requests.py # Request models (Pydantic v2)
188
+ │ └── responses.py # Response models (ResCat, ResFileDownload, etc.)
189
+ ├── tests/
190
+ │ ├── conftest.py
191
+ │ ├── test_client_auth.py
192
+ │ ├── test_initial_cats.py
193
+ │ ├── test_content_methods.py
194
+ │ ├── test_remaining_methods.py
195
+ │ ├── test_models_requests.py
196
+ │ ├── test_models_responses.py
197
+ │ ├── test_models_init.py
198
+ │ ├── test_endpoints.py
199
+ │ ├── test_retry.py
200
+ │ ├── test_token_refresh.py
201
+ │ └── test_examples.py
202
+ ├── examples/
203
+ │ ├── 01_auth.py
204
+ │ ├── 02_initial_cats.py
205
+ │ ├── 03_browse_category.py
206
+ │ ├── 04_search.py
207
+ │ ├── 05_upload.py
208
+ │ ├── 06_download.py
209
+ │ ├── 07_category_crud.py
210
+ │ └── 08_document_operations.py
211
+ ├── docs/
212
+ │ └── MIGRATION.md
213
+ ├── scripts/
214
+ │ └── docges_debug/ # Debug helpers for payload investigation
215
+ ├── pyproject.toml
216
+ ├── ruff.toml
217
+ ├── mypy.ini
218
+ └── README.md
219
+ ```
220
+
221
+ ## Contributing
222
+
223
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.