|
12 | 12 |
|
13 | 13 | # Python client for the gobbler service
|
14 | 14 |
|
15 |
| -Pretty much as it says on the can; provides an Python client for the [Gobbler service](https://github.com/ArtifactDB/gobbler). |
| 15 | +Pretty much as it says on the tin; provides an Python client for the [Gobbler service](https://github.com/ArtifactDB/gobbler), |
| 16 | +as a sister package to the corresponding [R client](https://github.com/ArtifactDB/gobbler-R). |
| 17 | +To demonstrate, let's spin up a mock Gobbler instance: |
| 18 | + |
| 19 | +```python |
| 20 | +import pygobbler as pyg |
| 21 | +_, staging, registry, url = pyg.start_gobbler() |
| 22 | +``` |
| 23 | + |
| 24 | +Administrators are responsible for creating projects: |
| 25 | + |
| 26 | +```python |
| 27 | +pyg.create_project("test", staging=staging, url=url, owners=["akari"]) |
| 28 | +``` |
| 29 | + |
| 30 | +An authorized user account (in this case, `akari`) can then upload directory of arbitrary files: |
| 31 | + |
| 32 | +```python |
| 33 | +import tempfile |
| 34 | +import os |
| 35 | +tmp = tempfile.mkdtemp() |
| 36 | +with open(os.path.join(tmp, "blah.txt"), "w") as f: |
| 37 | + f.write("BAR") |
| 38 | +os.mkdir(os.path.join(tmp, "foo")) |
| 39 | +with open(os.path.join(tmp, "foo", "bar.txt"), "w") as f: |
| 40 | + f.write("1 2 3 4 5 6 7 8 9 10") |
| 41 | + |
| 42 | +pyg.upload_directory( |
| 43 | + project="test", |
| 44 | + asset="foo", |
| 45 | + version="bar", |
| 46 | + directory=tmp, |
| 47 | + staging=staging, |
| 48 | + url=url |
| 49 | +) |
| 50 | +``` |
| 51 | + |
| 52 | +Anyone can fetch or list the contents, either on the same filesystem or remotely via the REST API. |
| 53 | + |
| 54 | +```python |
| 55 | +pyg.list_files("test", "foo", "bar", registry=registry, url=url) |
| 56 | +pyg.fetch_manifest("test", "foo", "bar", registry=registry, url=url) |
| 57 | +pyg.fetch_summary("test", "foo", "bar", registry=registry, url=url) |
| 58 | +pyg.version_path("test", "foo", "bar", registry=registry, url=url) |
| 59 | +``` |
| 60 | + |
| 61 | +Project owners can set the permissions to allow other users to add new assets or new versions of existing assets: |
| 62 | + |
| 63 | +```python |
| 64 | +pyg.set_permissions( |
| 65 | + "test", |
| 66 | + uploaders=[ { "id": "alicia", "asset": "foo" } ], |
| 67 | + registry=registry, |
| 68 | + staging=staging, |
| 69 | + url=url |
| 70 | +) |
| 71 | + |
| 72 | +# And then 'alicia' can do: |
| 73 | +pyg.upload_directory( |
| 74 | + project="test", |
| 75 | + asset="foo", |
| 76 | + version="bar2", |
| 77 | + directory=tmp, |
| 78 | + staging=staging, |
| 79 | + url=url |
| 80 | +) |
| 81 | +``` |
| 82 | + |
| 83 | +By default, `uploaders` are untrusted and their uploads will be "probational". |
| 84 | +Owners can approve/reject probational uploads after review. |
| 85 | + |
| 86 | +```python |
| 87 | +pyg.approve_probation("test", "foo", "bar2", staging=staging, url=url) |
| 88 | +``` |
| 89 | + |
| 90 | +Finally, administrators can delete projects, though this should be done sparingly. |
| 91 | + |
| 92 | +```python |
| 93 | +pyg.remove_project("test", staging=staging, url=url) |
| 94 | +``` |
| 95 | + |
| 96 | +Check out the [API documentation](https://artifactdb.github.io/gobbler-py/) for more details on each function. |
| 97 | +For the concepts underlying the Gobbler itself, check out the [repository](https://github.com/ArtifactDB/gobbler) for a detailed explanation. |
0 commit comments