Package: datadots-api
Datadots API for PythonSTATUS: What you currently see here is WIP, do not use in production!This is the Datadots API for Python, allowing you to access and manipulate dots against any Dotmesh cluster. Note that only Python 3 is supported.InstallUseCreate a dotCreate a dot in a namespaceLook up a dot by nameCommit to branch, show logCreate new branch based on latest masterEnd-to-end exampleTestReleaseInstallYou must have Python 3 installed, this is the only version supported.
Then do:$pip3installdatadots-api==0.1.4UseSome usage examples below.Create a dotfromdotmesh.clientimportDotmeshClientd=DotmeshClient(cluster_url=cluster_url,username=user,api_key=api_key)dot=dmclient.createDot(dotname="test")Create a dot in a namespacefromdotmesh.clientimportDotmeshClientd=DotmeshClient(cluster_url=cluster_url,username=user,api_key=api_key)dot=dmclient.createDot(dotname="test",ns="mynamespace")Look up a dot by namefromdotmesh.clientimportDotmeshClientd=DotmeshClient(cluster_url=cluster_url,username=user,api_key=api_key)print(d.getDot(dotname="test"))Commit to a branch and show the logfromdotmesh.clientimportDotmeshClientd=DotmeshClient(cluster_url=cluster_url,username=user,api_key=api_key)dot=dmclient.createDot(dotname="test")branch=dot.getBranch("master")branch.commit("just a test commit")print(branch.log())Commit to a branch with some extra metadatafromdotmesh.clientimportDotmeshClientd=DotmeshClient(cluster_url=cluster_url,username=user,api_key=api_key)dot=dmclient.createDot(dotname="test")branch=dot.getBranch("master")branch.commit("a commit with some extra metadata",{"fruit":"apples","color":"red"})print(branch.log())Create new branch based on latest masterfromdotmesh.clientimportDotmeshClientd=DotmeshClient(cluster_url=cluster_url,username=user,api_key=api_key)dot=dmclient.createDot(dotname="test")branch=dot.getBranch("master")branch.commit("just a test commit")mybranch=branch.createBranch("mybranch","master")mybranch.commit("the first commit in my branch")print(mybranch.log())End-to-end exampleYou can see this API in action, for a local setup with Docker running and after you've created a cluster usingdm cluster init, by running the followingexample:$DOTMESH_APIKEY=$(cat~/.dotmesh/config|jq-r.Remotes.local.ApiKey)$DOTMESH_APIKEY=$DOTMESH_APIKEYpython3example.py==Createdot:
-->{"jsonrpc":"2.0","method":"DotmeshRPC.Create","params":{"Namespace":"admin","Name":"test"},"id":1}<--{"jsonrpc":"2.0","result":true,"id":1}(200OK)-->{"jsonrpc":"2.0","method":"DotmeshRPC.Lookup","params":{"Namespace":"admin","Name":"test","Branch":""},"id":2}<--{"jsonrpc":"2.0","result":"32965cef-4310-4291-6f36-c86106655d10","id":2}(200OK)ID=32965cef-4310-4291-6f36-c86106655d10,name=test==Getmasterbranch:
-->{"jsonrpc":"2.0","method":"DotmeshRPC.Lookup","params":{"Namespace":"admin","Name":"test","Branch":""},"id":3}<--{"jsonrpc":"2.0","result":"32965cef-4310-4291-6f36-c86106655d10","id":3}(200OK)master==Dosomecommitandshowlog:
-->{"jsonrpc":"2.0","method":"DotmeshRPC.Commit","params":{"Namespace":"admin","Name":"test","Branch":"","Message":"just a test commit"},"id":4}<--{"jsonrpc":"2.0","result":true,"id":4}(200OK)-->{"jsonrpc":"2.0","method":"DotmeshRPC.Commit","params":{"Namespace":"admin","Name":"test","Branch":"","Message":"and another commit, who would have thought"},"id":5}<--{"jsonrpc":"2.0","result":true,"id":5}(200OK)-->{"jsonrpc":"2.0","method":"DotmeshRPC.Commits","params":{"Namespace":"admin","Name":"test","Branch":""},"id":6}<--{"jsonrpc":"2.0","result":[{"Id":"1007db99-11cb-4bd7-747e-1d121bb9b11a","Metadata":{"author":"admin","message":"just a test commit","timestamp":"1521214312285694689"}},{"Id":"67bb6184-430b-46d7-4337-b858ee85eb1c","Metadata":{"author":"admin","message":"and another commit, who would have thought","timestamp":"1521214312418429042"}}],"id":6}(200OK)1521214312285694689:justatestcommit1521214312418429042:andanothercommit,whowouldhavethought==Createnewbranch,commitandshowlog:
-->{"jsonrpc":"2.0","method":"DotmeshRPC.Commits","params":{"Namespace":"admin","Name":"test","Branch":""},"id":7}<--{"jsonrpc":"2.0","result":[{"Id":"1007db99-11cb-4bd7-747e-1d121bb9b11a","Metadata":{"author":"admin","message":"just a test commit","timestamp":"1521214312285694689"}},{"Id":"67bb6184-430b-46d7-4337-b858ee85eb1c","Metadata":{"author":"admin","message":"and another commit, who would have thought","timestamp":"1521214312418429042"}}],"id":7}(200OK)-->{"jsonrpc":"2.0","method":"DotmeshRPC.Branch","params":{"Namespace":"admin","Name":"test","SourceBranch":"master","NewBranchName":"mybranch","SourceCommitId":"67bb6184-430b-46d7-4337-b858ee85eb1c"},"id":8}<--{"jsonrpc":"2.0","result":true,"id":8}(200OK)-->{"jsonrpc":"2.0","method":"DotmeshRPC.Commit","params":{"Namespace":"admin","Name":"test","Branch":"mybranch","Message":"the first commit in my branch"},"id":9}<--{"jsonrpc":"2.0","result":true,"id":9}(200OK)-->{"jsonrpc":"2.0","method":"DotmeshRPC.Commits","params":{"Namespace":"admin","Name":"test","Branch":"mybranch"},"id":10}<--{"jsonrpc":"2.0","result":[{"Id":"565b04ab-abae-476a-75bd-203bce2a56b2","Metadata":{"author":"admin","message":"the first commit in my branch","timestamp":"1521214312967840418"}}],"id":10}(200OK)1521214312967840418:thefirstcommitinmybranchNote that the default behavior of the example above is to leave the dot in place, that is, if you do adm dot show testyou should see both themasterbranch andmybranchwith the commits. If you want to automatically clean up, execute it as follows:python3 example.py cleanup:$dmlist
Currentremote:local(use'dm remote -v'tolistand'dm remote switch'toswitch)DOTBRANCHSERVERCONTAINERSSIZECOMMITSDIRTY
*testmaster995e5c821c38e7f51.00kiB1-

$dmdotshowtestDotadmin/test:
MasterbranchID:7f4a4d67-5bc7-47aa-7829-31d5a02ff70f
Dotiscurrent.
Dotsize:1.00kiB(allclean)Branches:
*mastermybranch

$dmcheckoutmybranch&&dmlog
commit565b04ab-abae-476a-75bd-203bce2a56b2
Author:admin
Date:1521214312967840418thefirstcommitinmybranchTestLocally, you can test the Dotmesh JSON-RPC API like shown in the following. It assumes you've gothttpinstalled (or alternatively you can usecurl) as well as that Docker is running (note: tested on v18.03):$dmclusterinit
$DOTMESH_CLUSTERURL=http://localhost:6969/rpc
$DOTMESH_APIKEY=$(cat~/.dotmesh/config|jq-r.Remotes.local.ApiKey)$http-aadmin:$DOTMESH_APIKEYPOST$DOTMESH_CLUSTERURL<test/ping.json
HTTP/1.1200OK
Content-Length:57Content-Type:application/json;charset=utf-8
Date:Fri,16Mar201807:06:44GMT
X-Content-Type-Options:nosniff{"id":6129484611666146000,"jsonrpc":"2.0","result":true}ReleaseTo release this project to pypi, check the version (git tag and find the highest one, or check setup.py) then runbump2version --new-version <new-version> <major|minor|patch> && git push --tags