Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

How to connect to a remote hdfs (for example hortonworks VM) from a local machine in python

avatar
New Member

I want to read and write files to and from a remote HDFS. I program by Pycharm in local machine and I want to connect to a remote hdfs (HDP 2.5). Is there any solution?

How can I configure hdfs and how can I refer to a file in hdfs?

Thanks a million,

Shanghoosh

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Ali Mohammadi Shanghoshabad

Please check this article : https://community.hortonworks.com/articles/26416/how-to-install-snakebite-in-hdp.html You only need to pass the hdfs config files of your remote cluster to the python client.

.

For example in the python code :you can tell where is your core-site.xml /hdfs-site.xml present. It can be any path where these files are present.

https://github.com/spotify/snakebite/blob/6a456e6100b0c1be66cc1f7f9d7f50494f369da3/snakebite/client....

View solution in original post

2 REPLIES 2

avatar
Master Mentor

@Ali Mohammadi Shanghoshabad

Please check this article : https://community.hortonworks.com/articles/26416/how-to-install-snakebite-in-hdp.html You only need to pass the hdfs config files of your remote cluster to the python client.

.

For example in the python code :you can tell where is your core-site.xml /hdfs-site.xml present. It can be any path where these files are present.

https://github.com/spotify/snakebite/blob/6a456e6100b0c1be66cc1f7f9d7f50494f369da3/snakebite/client....

avatar
New Member

Hi @Jay SenSharma

Thank you for excellent notes.

I solved the problem before reading your notes as follows:

from hdfs import InsecureClient
client = InsecureClient('http://localhost:50070')
# for reading  a file
with client.read('/tmp/tweets_staging/tweets-082940117.json') as reader:
  features = reader.read()
# for writing a file
with client.write('/tmp/tweets_staging/1.json', overwrite=True) as writer:
   writer.write(features)

but I am going to try your solution too.

Regards,

Shanghoosh