Files¶
Document, FileResource, FileResourceDomain, and the FilesAccessor bound to Dhis2Client.files. Covers DHIS2's two file surfaces — documents (/api/documents) and file resources (/api/fileResources).
files
¶
Document management + typed file-resource upload/download.
Two orthogonal DHIS2 file surfaces, one accessor on Dhis2Client.files:
/api/documents— user-uploaded attachments tied to a CRUD metadata object. Types:UPLOAD_FILE(binary stored in DHIS2),EXTERNAL_URL(URL the DHIS2 UI links to). Appears in the DHIS2Data Administrationapp./api/fileResources— typed binary blobs referenced from other metadata:DATA_VALUE(file-type DataElement captures),ICON,MESSAGE_ATTACHMENT, etc. Create with adomain, get a UID back, then reference that UID from the owning resource.
Neither is part of the customize plugin — branding logos go through a
different endpoint family. This accessor is for operator-owned document
management + capture-media pipelines.
Classes¶
Document
¶
Bases: BaseModel
OpenAPI schema Document.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/document.py
FileResource
¶
Bases: BaseModel
OpenAPI schema FileResource.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/file_resource.py
FileResourceDomain
¶
Bases: StrEnum
FileResourceDomain.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/_enums.py
FilesAccessor
¶
Dhis2Client.files — documents + file resources.
All calls reuse the client's open HTTP pool + auth. Downloads buffer the response body into memory (DHIS2 documents + file resources are typically < 10 MB each); stream-download for larger payloads belongs on a follow-up when a real use case surfaces.
Source code in packages/dhis2w-client/src/dhis2w_client/files.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
Functions¶
__init__(client)
¶
list_documents(*, filter=None, page=None, page_size=None)
async
¶
List /api/documents — typed Document objects without the binary payload.
Source code in packages/dhis2w-client/src/dhis2w_client/files.py
get_document(uid)
async
¶
Return metadata for one document (/api/documents/{uid}).
upload_document(data, *, name, filename=None, content_type=None)
async
¶
Upload a binary as a DHIS2 document and return the created Document.
DHIS2 doesn't accept multipart-form POSTs on /api/documents
directly (415 Unsupported Media Type — see BUGS.md #16). The
correct workflow is a two-step:
- Upload the bytes as a
FileResourcewithdomain=DOCUMENTvia/api/fileResources. POST /api/documents(JSON) withurl=<fileResourceUid>so the document references the already-stored file resource.
contentType is inferred from filename when not set. The
returned Document carries the new UID.
Source code in packages/dhis2w-client/src/dhis2w_client/files.py
create_external_document(*, name, url)
async
¶
Create an EXTERNAL_URL document (no binary; DHIS2 links to url).
Source code in packages/dhis2w-client/src/dhis2w_client/files.py
download_document(uid)
async
¶
Fetch the binary payload at /api/documents/{uid}/data.
Source code in packages/dhis2w-client/src/dhis2w_client/files.py
delete_document(uid)
async
¶
upload_file_resource(data, *, filename, domain=FileResourceDomain.DATA_VALUE, content_type=None)
async
¶
Upload a file resource and return the created FileResource.
domain picks the storage family (DATA_VALUE for file-type DE
captures, ICON for custom icons, MESSAGE_ATTACHMENT, etc.).
DHIS2 returns a WebMessage envelope with the created UID under
response.fileResource.id (NOT response.uid like /api/documents).
The returned FileResource is then the UID you reference from
the owning resource.
Source code in packages/dhis2w-client/src/dhis2w_client/files.py
get_file_resource(uid)
async
¶
Return metadata for one file resource (/api/fileResources/{uid}).
download_file_resource(uid)
async
¶
Fetch the binary payload at /api/fileResources/{uid}/data.