snowflake.core.stage.StageResource¶
- class snowflake.core.stage.StageResource(name: str, collection: StageCollection)¶
Bases:
SchemaObjectReferenceMixin
[StageCollection
]Represents a reference to a Snowflake Stage resource.
Attributes
- database¶
- fully_qualified_name¶
- root¶
- schema¶
Methods
- __init__(name: str, collection: StageCollection) None ¶
- delete() None ¶
Delete the stage.
- download_file(stage_path: str, file_folder_path: str) None ¶
Download a file from a stage location.
Currently only supports downloading files smaller than 1MB from server-side encrypted stages.
- Parameters:
stage_path – The stage location of the file to be downloaded from.
file_folder_path – A string representing the folder location of the file to be written to.
- drop() None ¶
Drop the stage.
- get(stage_location: str, target_directory: str | PathLike, *, parallel: int = 4, pattern: str | None = None) None ¶
Download the specified files from a path in the stage to a local directory.
References: Snowflake GET command.
- Parameters:
stage_location – A directory or filename on a stage, from which you want to download the files. e.g. /folder/file_name.txt or /folder
target_directory – The path to the local directory where the files should be downloaded. If
target_directory
does not already exist, the method creates the directory.parallel – Specifies the number of threads to use for downloading the files. The granularity unit for downloading is one file. Increasing the number of threads might improve performance when downloading large files. Valid values: Any integer value from 1 (no parallelism) to 99 (use 99 threads for downloading files).
pattern – Specifies a regular expression pattern for filtering files to download. The command lists all files in the specified path and applies the regular expression pattern on each of the files found. Default:
None
(all files in the specified stage are downloaded).
- list_files(*, pattern: str | None = None) Iterator[StageFile] ¶
List files in the stage.
- Parameters:
pattern – Specifies a regular expression pattern for filtering files from the output.
each (The command lists all files in the specified path and applies the regular expression pattern on)
found. (of the files)
- put(local_file_name: str | PathLike, stage_location: str, *, parallel: int = 4, auto_compress: bool = True, source_compression: str = 'AUTO_DETECT', overwrite: bool = False) None ¶
Upload local files to a path in the stage.
References: Snowflake PUT command.
- Parameters:
local_file_name – The path to the local files to upload. To match multiple files in the path, you can specify the wildcard characters
*
and?
.stage_location – The prefix where you want to upload the files. e.g. /folder or /
parallel –
Specifies the number of threads to use for uploading files. The upload process separates batches of data files by size:
Small files (< 64 MB) are staged in parallel as individual files.
Larger files are automatically split into chunks, staged concurrently, and reassembled in the target stage. A single thread can upload multiple chunks.
Increasing the number of threads can improve performance when uploading large files. Supported values: Any integer value from 1 (no parallelism) to 99 (use 99 threads for uploading files).
auto_compress – Specifies whether Snowflake uses gzip to compress files during upload.
source_compression – Specifies the method of compression used on already-compressed files that are being staged. Values can be ‘AUTO_DETECT’, ‘GZIP’, ‘BZ2’, ‘BROTLI’, ‘ZSTD’, ‘DEFLATE’, ‘RAW_DEFLATE’, ‘NONE’.
overwrite – Specifies whether Snowflake will overwrite an existing file with the same name during upload.
- upload_file(file_path: str, stage_folder_path: str, *, auto_compress: bool = True, overwrite: bool = False) None ¶
Upload a file to a stage location.
Currently only supports uploading files smaller than 1MB to server-side encrypted stages.
- Parameters:
file_path – A string representing the location of the file on the client machine to be uploaded.
stage_folder_path – The stage folder location to be uploaded to, e.g. /folder or /
auto_compress –
Specifies whether Snowflake uses gzip to compress files during upload: True: Snowflake compresses the files (if they are not already compressed).
False: Snowflake does not compress the files.
overwrite –
Specifies whether Snowflake overwrites an existing file with the same name during upload: True: An existing file with the same name is overwritten.
False: An existing file with the same name is not overwritten.
Raise APIError if upload failed