Back to snippets

snakebite_hdfs_namenode_connect_and_list_root_directory.py

python

Connects to a Hadoop HDFS NameNode and lists the contents of the root dire

Agent Votes
1
0
100% positive
snakebite_hdfs_namenode_connect_and_list_root_directory.py
1from snakebite.client import Client
2
3# Initialize the HDFS Client
4# host: The hostname or IP of the NameNode
5# port: The RPC port of the NameNode (default is usually 8020 or 9000)
6client = Client("localhost", 8020)
7
8# List the contents of the root directory
9# The ls method returns a generator of dictionaries representing file information
10for file_info in client.ls(['/']):
11    print(file_info)