Created
September 29, 2022 11:14
-
-
Save rjrudin/46011bd6daee06b1de39b633e741e0d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
batch = DocumentBatch() | |
# Document with every type of metadata supplied | |
batch.add( | |
Document( | |
uri="/example1.json", | |
content={"some": "data"}, | |
content_type="application/json", | |
metadata=Metadata( | |
quality=1.2, | |
collections=["coll1", "coll2"], | |
permissions={ | |
"rest-reader": ["read", "execute"], | |
"rest-writer": "update", | |
}, | |
properties={ | |
"prop1": "simple value", | |
"prop2": "<nested><xml>will work</xml></nested>", | |
}, | |
metadataValues={"key1": "value1", "key2": "value2"}, | |
), | |
) | |
) | |
# Minimal example of creating a document | |
batch.add( | |
Document( | |
uri="/example2.xml", | |
content="<some>xml</some>", | |
content_type="application/xml", | |
), | |
) | |
data, headers = batch.data_and_headers() | |
response = requests.post( | |
"http://localhost:8000/v1/documents", | |
auth=HTTPDigestAuth("admin", "admin"), | |
data=data, | |
headers=headers, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implementing this can be done by copying the excellent work at marklogic/python_api - specifically in https://github.com/marklogic/python_api/blob/master/marklogic/client/bulkloader.py and https://github.com/marklogic/python_api/blob/master/marklogic/client/documents.py
Note that that project has a much larger scope, covering parts of the Manage API and Client API. Additionally, the
Documents
class serves two purposes - one as a facade on /v1/documents, and also for holding bits about a single document.