datpyThis notebook gets you started with datpy, the python client for dat.
For all of the functionality, read the documentation on the GitHub repository at https://github.com/karissa/datpy
In [53]:
import datpy
import os
dat = datpy.Dat()
We have some data in the 'examples' folder. Let's create a dat link for it.
In [54]:
os.listdir('examples')
Out[54]:
In [55]:
fp = open('examples/kiwi.json', 'r')
fp.read()
Out[55]:
In [56]:
link = dat.link('examples')
In [57]:
link
Out[57]:
Dat has opened TCP servers that will rehost the data to any peers who connect to the network, that works like BitTorrent. This link can be used to download the data to another location, let's say, the data folder. To share with users on other networks, you may need to open port 3282.
In [58]:
dat.download(link, 'data')
Out[58]:
Now, if we look inside the data folder, we will find the same data we had in the examples folder. Note that dat downloads the data into a subfolder.
In [59]:
os.listdir('data/examples')
Out[59]:
In [60]:
fp = open('data/examples/kiwi.json', 'r')
fp.read()
Out[60]:
Dat keeps track of all of the subprocesses it opens. They can be closed manually, or will be closed when your python process ends.
In [61]:
dat._opened
Out[61]:
Here, we will close them manually.
In [62]:
dat.close()
Out[62]:
For all of the functionality, read the documentation on the GitHub repository at https://github.com/karissa/datpy
In [ ]: