Quickstart with datpy

This 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]:
['blob.txt', 'contracts.csv', 'kiwi.json']

In [55]:
fp = open('examples/kiwi.json', 'r')
fp.read()


Out[55]:
'{"fruit":"kiwi"}'

In [56]:
link = dat.link('examples')

In [57]:
link


Out[57]:
u'dat://9e991b518925721eb0de1a31df7ca47736c398d18918543d28c63d104fb36a0c'

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]:
True

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]:
['blob.txt', 'contracts.csv', 'kiwi.json']

In [60]:
fp = open('data/examples/kiwi.json', 'r')
fp.read()


Out[60]:
'{"fruit":"kiwi"}'

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]:
[<subprocess.Popen at 0x105353ed0>, <subprocess.Popen at 0x105353e90>]

Here, we will close them manually.


In [62]:
dat.close()


Out[62]:
True

For all of the functionality, read the documentation on the GitHub repository at https://github.com/karissa/datpy


In [ ]: