|
| 1 | +from nisystemlink.clients.core import HttpConfiguration |
| 2 | +from nisystemlink.clients.notebook import NotebookClient |
| 3 | +from nisystemlink.clients.notebook.models import NotebookMetadata, QueryNotebookRequest |
| 4 | + |
| 5 | +# Setup the server configuration to point to your instance of SystemLink Enterprise |
| 6 | +server_configuration = HttpConfiguration( |
| 7 | + server_uri="https://yourserver.yourcompany.com", |
| 8 | + api_key="YourAPIKeyGeneratedFromSystemLink", |
| 9 | +) |
| 10 | +client = NotebookClient(configuration=server_configuration) |
| 11 | + |
| 12 | +# Create a notebook with metadata and content |
| 13 | +metadata = NotebookMetadata( |
| 14 | + name="Example Notebook", |
| 15 | + parameters={"param1": "value1"}, |
| 16 | + properties={"property1": "value1"}, |
| 17 | +) |
| 18 | + |
| 19 | +with open("example.ipynb", "rb") as file: |
| 20 | + notebook_response = client.create_notebook(metadata=metadata, content=file) |
| 21 | + |
| 22 | +# Get the notebook by ID |
| 23 | +notebook = client.get_notebook("your_notebook_id") |
| 24 | + |
| 25 | +# Update the notebook with new metadata and content |
| 26 | +metadata = NotebookMetadata( |
| 27 | + name="Updated Example Notebook", |
| 28 | + parameters={"param1": "value2"}, |
| 29 | + properties={"property1": "value2"}, |
| 30 | +) |
| 31 | + |
| 32 | +with open("example_updated.ipynb", "rb") as file: |
| 33 | + notebook_response = client.update_notebook( |
| 34 | + id="your_notebook_id", |
| 35 | + metadata=metadata, |
| 36 | + content=file, |
| 37 | + ) |
| 38 | + |
| 39 | +# Get notebook content by ID |
| 40 | +notebook_content = client.get_notebook_content("your_notebook_id") |
| 41 | + |
| 42 | +# Query notebook by name |
| 43 | +query_request = QueryNotebookRequest( |
| 44 | + filter='name="Example Notebook"', |
| 45 | +) |
| 46 | + |
| 47 | +query_response = client.query_notebooks(query_request) |
| 48 | + |
| 49 | +# Query notebooks by take |
| 50 | +query_request = QueryNotebookRequest(take=2) |
| 51 | +query_response = client.query_notebooks(query_request) |
| 52 | + |
| 53 | +query_request = QueryNotebookRequest( |
| 54 | + continuation_token=query_response.continuation_token, |
| 55 | + take=1, |
| 56 | +) |
| 57 | +query_response = client.query_notebooks(query_request) |
| 58 | + |
| 59 | +# Delete the notebook by ID |
| 60 | +client.delete_notebook("your_notebook_id") |
0 commit comments