Create py39-ml-connect.ipynb
Browse files- py39-ml-connect.ipynb +42 -0
py39-ml-connect.ipynb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!python3.9 --version
|
| 2 |
+
!pip3.9 install marklogic-python-client
|
| 3 |
+
|
| 4 |
+
from marklogic import Client
|
| 5 |
+
from marklogic.documents import Document, DefaultMetadata
|
| 6 |
+
|
| 7 |
+
client = Client('http://localhost:8000', digest=('python-user', 'pyth0n'))
|
| 8 |
+
client.documents.write([
|
| 9 |
+
DefaultMetadata(permissions={"rest-reader": ["read", "update"]}, collections=["python-example"]),
|
| 10 |
+
Document("/doc1.json", {"text": "example one"}),
|
| 11 |
+
Document("/doc2.xml", "<text>example two</text>"),
|
| 12 |
+
Document("/doc3.bin", b"binary example", permissions={"rest-reader": ["read", "update"]})
|
| 13 |
+
])
|
| 14 |
+
|
| 15 |
+
client = Client('http://localhost:8000', digest=('python-user', 'pyth0n'))
|
| 16 |
+
client.documents.write([
|
| 17 |
+
DefaultMetadata(permissions={"rest-reader": ["read", "update"]}, collections=["python-example"]),
|
| 18 |
+
Document("/doc1.json", {"text": "example one"}),
|
| 19 |
+
Document("/doc2.xml", "<text>example two</text>"),
|
| 20 |
+
Document("/doc3.bin", b"binary example", permissions={"rest-reader": ["read", "update"]})
|
| 21 |
+
])
|
| 22 |
+
|
| 23 |
+
doc = docs[0]
|
| 24 |
+
print(doc)
|
| 25 |
+
|
| 26 |
+
# Can always built-in Python vars method.
|
| 27 |
+
print(vars(doc))
|
| 28 |
+
|
| 29 |
+
uris = ["/doc1.json", "/doc2.xml", "/doc3.bin"]
|
| 30 |
+
|
| 31 |
+
# Retrieve content and all metadata for each document.
|
| 32 |
+
docs = client.documents.read(uris, categories=["content", "metadata"])
|
| 33 |
+
print(docs)
|
| 34 |
+
|
| 35 |
+
# Retrieve content, collections, and permissions for each document.
|
| 36 |
+
docs = client.documents.read(uris, categories=["content", "collections", "permissions"])
|
| 37 |
+
print(docs)
|
| 38 |
+
|
| 39 |
+
# Retrieve only collections for each document; the content attribute will be None.
|
| 40 |
+
docs = client.documents.read(uris, categories=["collections"])
|
| 41 |
+
print(docs)
|
| 42 |
+
|