forked from databricks/databricks-sql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming_put.py
More file actions
36 lines (28 loc) · 963 Bytes
/
streaming_put.py
File metadata and controls
36 lines (28 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""
Simple example of streaming PUT operations.
This demonstrates the basic usage of streaming PUT with the __input_stream__ token.
"""
import io
import os
from databricks import sql
def main():
"""Simple streaming PUT example."""
# Connect to Databricks
connection = sql.connect(
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
access_token=os.getenv("DATABRICKS_TOKEN"),
)
with connection.cursor() as cursor:
# Create a simple data stream
data = b"Hello, streaming world!"
stream = io.BytesIO(data)
# Upload to Unity Catalog volume
cursor.execute(
"PUT '__input_stream__' INTO '/Volumes/my_catalog/my_schema/my_volume/hello.txt'",
input_stream=stream
)
print("File uploaded successfully!")
if __name__ == "__main__":
main()