QuickstartΒΆ

Import hdfs3 and connect to an HDFS cluster:

>>> from hdfs3 import HDFileSystem
>>> hdfs = HDFileSystem(host='localhost', port=8020)

Write data to file:

>>> with hdfs.open('/tmp/myfile.txt', 'wb') as f:
...     f.write(b'Hello, world!')

Read data back from file:

>>> with hdfs.open('/tmp/myfile.txt') as f:
...     print(f.read())

Interact with files on HDFS:

>>> hdfs.ls('/tmp')

>>> hdfs.put('local-file.txt', '/tmp/remote-file.txt')

>>> hdfs.cp('/tmp/remote-file.txt', '/tmp/copied-file.txt')