Skip to content

Commit c179c2d

Browse files
authored
Merge pull request #251646 from pauljewellmsft/python-version
Update required version for Python / remove deprecated samples from main article
2 parents f632e88 + 6c52203 commit c179c2d

File tree

4 files changed

+6
-211
lines changed

4 files changed

+6
-211
lines changed

articles/storage/blobs/storage-blob-python-get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This article shows you how to connect to Azure Blob Storage by using the Azure B
2222

2323
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
2424
- Azure storage account - [create a storage account](../common/storage-account-create.md)
25-
- [Python](https://www.python.org/downloads/) 3.6+
25+
- [Python](https://www.python.org/downloads/) 3.7+
2626

2727
## Set up your project
2828

articles/storage/blobs/storage-quickstart-blobs-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Get started with the Azure Blob Storage client library for Python to manage blob
2222

2323
- Azure account with an active subscription - [create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio)
2424
- Azure Storage account - [create a storage account](../common/storage-account-create.md)
25-
- [Python](https://www.python.org/downloads/) 3.6+
25+
- [Python](https://www.python.org/downloads/) 3.7+
2626

2727
## Setting up
2828

articles/storage/files/storage-python-how-to-use-file-storage.md

Lines changed: 3 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ms.custom: devx-track-python, py-fresh-zinc
1515

1616
[!INCLUDE [storage-selector-file-include](../../../includes/storage-selector-file-include.md)]
1717

18-
Learn the basics of using Python to develop apps or services that use Azure Files to store file data. Create a simple console app and learn how to perform basic actions with Python and Azure Files:
18+
Learn the basics of using Python to develop apps or services that use Azure Files to store file data. Create a console app and learn how to perform basic actions with Python and Azure Files:
1919

2020
- Create Azure file shares
2121
- Create directories
@@ -38,310 +38,105 @@ Learn the basics of using Python to develop apps or services that use Azure File
3838
> [!NOTE]
3939
> If you are upgrading from the Azure Storage SDK for Python version 0.36 or earlier, uninstall the older SDK using `pip uninstall azure-storage` before installing the latest package.
4040
41-
# [Azure Python SDK v12](#tab/python)
42-
43-
The [Azure Files client library v12.x for Python](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-file-share) requires Python 2.7 or 3.6+.
44-
45-
# [Azure Python SDK v2](#tab/python2)
46-
47-
The [Azure Storage SDK for Python](https://github.com/azure/azure-storage-python) requires Python 2.7 or 3.6+.
48-
49-
---
41+
The [Azure Files client library for Python](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-file-share) requires Python 3.7+.
5042

5143
## Install via PyPI
5244

5345
To install via the Python Package Index (PyPI), type:
5446

55-
# [Azure Python SDK v12](#tab/python)
56-
5747
```console
5848
pip install azure-storage-file-share
5949
```
6050

61-
# [Azure Python SDK v2](#tab/python2)
62-
63-
```console
64-
pip install azure-storage-file
65-
```
66-
67-
### View the sample application
68-
69-
To view and run a sample application that shows how to use Python with Azure Files, see [Azure Storage: Getting Started with Azure Files in Python](https://github.com/Azure-Samples/storage-file-python-getting-started).
70-
71-
To run the sample application, make sure you've installed both the `azure-storage-file` and `azure-storage-common` packages.
72-
73-
---
74-
7551
## Set up your application to use Azure Files
7652

77-
Add the following near the top of a Python source file to use the code snippets in this article.
78-
79-
# [Azure Python SDK v12](#tab/python)
53+
Add the following code near the top of a Python source file to use the code snippets in this article.
8054

8155
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_Imports":::
8256

83-
# [Azure Python SDK v2](#tab/python2)
84-
85-
```python
86-
from azure.storage.file import FileService
87-
```
88-
89-
---
90-
9157
## Set up a connection to Azure Files
9258

93-
# [Azure Python SDK v12](#tab/python)
94-
9559
[ShareServiceClient](/azure/developer/python/sdk/storage/azure-storage-file-share/azure.storage.fileshare.shareserviceclient) lets you work with shares, directories, and files. This code creates a `ShareServiceClient` object using the storage account connection string:
9660

9761
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_CreateShareServiceClient":::
9862

99-
# [Azure Python SDK v2](#tab/python2)
100-
101-
The [FileService](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice) object lets you work with shares, directories, and files. The following code creates a `FileService` object using the storage account name and account key. Replace `<myaccount>` and `<mykey>` with your account name and key.
102-
103-
```python
104-
file_service = FileService(account_name='myaccount', account_key='mykey')
105-
```
106-
107-
---
108-
10963
## Create an Azure file share
11064

111-
# [Azure Python SDK v12](#tab/python)
112-
11365
The following code example uses a [ShareClient](/azure/developer/python/sdk/storage/azure-storage-file-share/azure.storage.fileshare.shareclient) object to create the share if it doesn't exist.
11466

11567
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_CreateFileShare":::
11668

117-
# [Azure Python SDK v2](#tab/python2)
118-
119-
The following code example uses a [FileService](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice) object to create the share if it doesn't exist.
120-
121-
```python
122-
file_service.create_share('myshare')
123-
```
124-
125-
---
126-
12769
## Create a directory
12870

12971
You can organize storage by putting files inside subdirectories instead of having all of them in the root directory.
13072

131-
# [Azure Python SDK v12](#tab/python)
132-
13373
The following method creates a directory in the root of the specified file share by using a [ShareDirectoryClient](/azure/developer/python/sdk/storage/azure-storage-file-share/azure.storage.fileshare.sharedirectoryclient) object.
13474

13575
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_CreateDirectory":::
13676

137-
# [Azure Python SDK v2](#tab/python2)
138-
139-
This code creates a subdirectory named *sampledir* under the root directory:
140-
141-
```python
142-
file_service.create_directory('myshare', 'sampledir')
143-
```
144-
145-
---
146-
14777
## Upload a file
14878

14979
In this section, you learn how to upload a file from local storage into Azure Files.
15080

151-
# [Azure Python SDK v12](#tab/python)
152-
15381
The following method uploads the contents of the specified file into the specified directory in the specified Azure file share.
15482

15583
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_UploadFile":::
15684

157-
# [Azure Python SDK v2](#tab/python2)
158-
159-
An Azure file share contains, at the least, a root directory where files can reside. To create a file and upload data, use the [create_file_from_path](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-create-file-from-path), [create_file_from_stream](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-create-file-from-stream), [create_file_from_bytes](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-create-file-from-bytes), or [create_file_from_text](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-create-file-from-text) methods. They're high-level methods that perform the necessary chunking when the size of the data exceeds 64 MiB.
160-
161-
`create_file_from_path` uploads the contents of a file from the specified path, and `create_file_from_stream` uploads the contents from an already opened file/stream. `create_file_from_bytes` uploads an array of bytes, and `create_file_from_text` uploads the specified text value using the specified encoding (defaults to UTF-8).
162-
163-
The following example uploads the contents of the *sunset.png* file into the **myfile** file.
164-
165-
```python
166-
from azure.storage.file import ContentSettings
167-
file_service.create_file_from_path(
168-
'myshare',
169-
None, # We want to create this file in the root directory, so we specify None for the directory_name
170-
'myfile',
171-
'sunset.png',
172-
content_settings=ContentSettings(content_type='image/png'))
173-
```
174-
175-
---
176-
17785
## Enumerate files and directories in an Azure file share
17886

179-
# [Azure Python SDK v12](#tab/python)
180-
18187
To list the files and directories in a subdirectory, use the [list_directories_and_files](/python/api/azure-storage-file-share/azure.storage.fileshare.ShareClient#azure-storage-fileshare-shareclient-list-directories-and-files) method. This method returns an auto-paging iterable. The following code outputs the **name** of each file and subdirectory in the specified directory to the console.
18288

18389
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_ListFilesAndDirs":::
18490

185-
# [Azure Python SDK v2](#tab/python2)
186-
187-
To list the files and directories in a share, use the [list_directories_and_files](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-list-directories-and-files) method. This method returns a generator. The following code outputs the **name** of each file and directory in a share to the console.
188-
189-
```python
190-
generator = file_service.list_directories_and_files('myshare')
191-
for file_or_dir in generator:
192-
print(file_or_dir.name)
193-
```
194-
195-
---
196-
19791
## Download a file
19892

199-
# [Azure Python SDK v12](#tab/python)
200-
20193
To download data from a file, use [download_file](/python/api/azure-storage-file-share/azure.storage.fileshare.ShareFileClient#azure-storage-fileshare-sharefileclient-download-file).
20294

20395
The following example demonstrates using `download_file` to get the contents of the specified file and store it locally with **DOWNLOADED-** prepended to the filename.
20496

20597
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_DownloadFile":::
20698

207-
# [Azure Python SDK v2](#tab/python2)
208-
209-
To download data from a file, use [get_file_to_path](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-get-file-to-path), [get_file_to_stream](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#get-file-to-stream-share-name--directory-name--file-name--stream--start-range-none--end-range-none--validate-content-false--progress-callback-none--max-connections-2--timeout-none--snapshot-none-), [get_file_to_bytes](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-get-file-to-bytes), or [get_file_to_text](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-get-file-to-text). They're high-level methods that perform the necessary chunking when the size of the data exceeds 64 MiB.
210-
211-
The following example demonstrates using `get_file_to_path` to download the contents of the **myfile** file and store it to the *out-sunset.png* file.
212-
213-
```python
214-
file_service.get_file_to_path('myshare', None, 'myfile', 'out-sunset.png')
215-
```
216-
217-
---
218-
21999
## Create a share snapshot
220100

221101
You can create a point in time copy of your entire file share.
222102

223-
# [Azure Python SDK v12](#tab/python)
224-
225103
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_CreateSnapshot":::
226104

227-
# [Azure Python SDK v2](#tab/python2)
228-
229-
```python
230-
snapshot = file_service.snapshot_share(share_name)
231-
snapshot_id = snapshot.snapshot
232-
```
233-
234-
**Create share snapshot with metadata**
235-
236-
```python
237-
metadata = {"foo": "bar"}
238-
snapshot = file_service.snapshot_share(share_name, metadata=metadata)
239-
```
240-
241-
---
242-
243105
## List shares and snapshots
244106

245107
You can list all the snapshots for a particular share.
246108

247-
# [Azure Python SDK v12](#tab/python)
248-
249109
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_ListSharesAndSnapshots":::
250110

251-
# [Azure Python SDK v2](#tab/python2)
252-
253-
```python
254-
shares = list(file_service.list_shares(include_snapshots=True))
255-
```
256-
257-
---
258-
259111
## Browse share snapshot
260112

261113
You can browse each share snapshot to retrieve files and directories from that point in time.
262114

263-
# [Azure Python SDK v12](#tab/python)
264-
265115
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_BrowseSnapshotDir":::
266116

267-
# [Azure Python SDK v2](#tab/python2)
268-
269-
```python
270-
directories_and_files = list(
271-
file_service.list_directories_and_files(share_name, snapshot=snapshot_id))
272-
```
273-
274-
---
275-
276117
## Get file from share snapshot
277118

278119
You can download a file from a share snapshot, which enables you to restore a previous version of a file.
279120

280-
# [Azure Python SDK v12](#tab/python)
281-
282121
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_DownloadSnapshotFile":::
283122

284-
# [Azure Python SDK v2](#tab/python2)
285-
286-
```python
287-
with open(FILE_PATH, 'wb') as stream:
288-
file = file_service.get_file_to_stream(
289-
share_name, directory_name, file_name, stream, snapshot=snapshot_id)
290-
```
291-
292-
---
293-
294123
## Delete a single share snapshot
295124
You can delete a single share snapshot.
296125

297-
# [Azure Python SDK v12](#tab/python)
298-
299126
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_DeleteSnapshot":::
300127

301-
# [Azure Python SDK v2](#tab/python2)
302-
303-
```python
304-
file_service.delete_share(share_name, snapshot=snapshot_id)
305-
```
306-
307-
---
308-
309128
## Delete a file
310129

311-
# [Azure Python SDK v12](#tab/python)
312-
313130
To delete a file, call [delete_file](/python/api/azure-storage-file-share/azure.storage.fileshare.ShareFileClient#azure-storage-fileshare-sharefileclient-delete-file).
314131

315132
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_DeleteFile":::
316133

317-
# [Azure Python SDK v2](#tab/python2)
318-
319-
To delete a file, call [delete_file](/python/api/azure-storage-file/azure.storage.file.fileservice.fileservice#azure-storage-file-fileservice-fileservice-delete-file).
320-
321-
```python
322-
file_service.delete_file('myshare', None, 'myfile')
323-
```
324-
325-
---
326-
327134
## Delete share when share snapshots exist
328135

329-
# [Azure Python SDK v12](#tab/python)
330-
331136
To delete a share that contains snapshots, call [delete_share](/python/api/azure-storage-file-share/azure.storage.fileshare.ShareClient#azure-storage-fileshare-shareclient-delete-share) with `delete_snapshots=True`.
332137

333138
:::code language="python" source="~/azure-storage-snippets/files/howto/python/python-v12/file_share_ops.py" id="Snippet_DeleteShare":::
334139

335-
# [Azure Python SDK v2](#tab/python2)
336-
337-
A share that contains snapshots can't be deleted unless all the snapshots are deleted first.
338-
339-
```python
340-
file_service.delete_share(share_name, delete_snapshots=DeleteSnapshot.Include)
341-
```
342-
343-
---
344-
345140
## Next steps
346141

347142
Now that you've learned how to manipulate Azure Files with Python, follow these links to learn more.

articles/storage/queues/storage-quickstart-queues-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Use the Azure Queue Storage client library for Python to:
3333

3434
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
3535
- Azure Storage account - [create a storage account](../common/storage-account-create.md)
36-
- [Python](https://www.python.org/downloads/) 3.6+
36+
- [Python](https://www.python.org/downloads/) 3.7+
3737

3838
## Setting up
3939

0 commit comments

Comments
 (0)