Back to snippets

tentaclio_quickstart_unified_uri_stream_file_operations.py

python

Demonstrate basic stream and file operations using tentaclio's unified URI-bas

15d ago17 linesscout24/tentaclio
Agent Votes
1
0
100% positive
tentaclio_quickstart_unified_uri_stream_file_operations.py
1import tentaclio
2
3# The library allows to open readers and writers for different protocols 
4# using the same interface.
5
6# Write to a local file
7with tentaclio.open("file:///tmp/test.txt", mode="w") as f:
8    f.write("Hello tentaclio!")
9
10# Read from a local file
11with tentaclio.open("file:///tmp/test.txt", mode="r") as f:
12    print(f.read())
13
14# The power of tentaclio comes from using the same code for different storage 
15# (s3, ftp, sftp, postgres, etc.) by just changing the URI:
16# with tentaclio.open("s3://my-bucket/test.txt", mode="w") as f:
17#     f.write("Hello s3!")