访问hadoophttprestapi的包装库
webhdfsp的Python项目详细描述
的python 2/3包装库
安装
从pypi安装webhdfspy:
$ pip install webhdfspy
python版本
webhdfspy支持python 2.7和3.4
用法
>>> import webhdfspy >>> webHDFS = webhdfspy.WebHDFSClient("localhost", 50070, "username") >>> print(webHDFS.listdir('/')) [] >>> webHDFS.mkdir('/foo') True >>> print(webHDFS.listdir('/')) [{u'group': u'supergroup', u'permission': u'755', u'blockSize': 0, u'accessTime': 0, u'pathSuffix': u'foo', u'modificationTime': 1429805040695, u'replication': 0, u'length': 0, u'childrenNum': 0, u'owner': u'username', u'storagePolicy': 0, u'type': u'DIRECTORY', u'fileId': 16387}] >>> print webHDFS.create('/foo/foo.txt', "just put some text here", True) True >>> print webHDFS.open('/pywebhdfs_test/foo.txt') just put some text here >>> webHDFS.remove('/foo') True >>> print(webHDFS.listdir('/')) []
Hadoop配置
要在hadoop中启用webhdfs,请将其添加到$hadoop目录/conf/hdfs-site.xml中:
<property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property>
要在hdfs上启用append,您需要如下配置hdfs-site.xml:
<property> <name>dfs.support.append</name> <value>true</value> </property>
关于webhdfs的更多信息:https://hadoop.apache.org/docs/r1.0.4/webhdfs.html