prefect_azure
AzureBlobStorageContainer
Bases: ObjectStorageBlock
, WritableFileSystem
, WritableDeploymentStorage
Represents a container in Azure Blob Storage.
This class provides methods for downloading and uploading files and folders to and from the Azure Blob Storage container.
Attributes:
Name | Type | Description |
---|---|---|
container_name |
str
|
The name of the Azure Blob Storage container. |
credentials |
AzureBlobStorageCredentials
|
The credentials to use for authentication with Azure. |
base_folder |
Optional[str]
|
A base path to a folder within the container to use for reading and writing objects. |
Source code in prefect_azure/blob_storage.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
download_folder_to_path(from_folder, to_folder, **download_kwargs)
async
Download a folder from the container to a local path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_folder
|
str
|
The folder path in the container to download. |
required |
to_folder
|
Union[str, Path]
|
The local path to download the folder to. |
required |
**download_kwargs
|
Dict[str, Any]
|
Additional keyword arguments passed into
|
{}
|
Returns:
Type | Description |
---|---|
Coroutine[Any, Any, Path]
|
The local path where the folder was downloaded. |
Example
Download the contents of container folder folder
from the container
to the local folder local_folder
:
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
block.download_folder_to_path(
from_folder="folder",
to_folder="local_folder"
)
Source code in prefect_azure/blob_storage.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
download_object_to_file_object(from_path, to_file_object, **download_kwargs)
async
Downloads an object from the container to a file object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_path
|
The path of the object to download within the container. |
required | |
to_file_object
|
BinaryIO
|
The file object to download the object to. |
required |
**download_kwargs
|
Dict[str, Any]
|
Additional keyword arguments for the download operation. |
{}
|
Returns:
Type | Description |
---|---|
Coroutine[Any, Any, BinaryIO]
|
The file object that the object was downloaded to. |
Example
Download the object object
from the container to a file object:
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
with open("file.txt", "wb") as f:
block.download_object_to_file_object(
from_path="object",
to_file_object=f
)
Source code in prefect_azure/blob_storage.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
download_object_to_path(from_path, to_path, **download_kwargs)
async
Downloads an object from a container to a specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_path
|
str
|
The path of the object in the container. |
required |
to_path
|
Union[str, Path]
|
The path where the object will be downloaded to. |
required |
**download_kwargs
|
Dict[str, Any]
|
Additional keyword arguments for the download operation. |
{}
|
Returns:
Type | Description |
---|---|
Coroutine[Any, Any, Path]
|
The path where the object was downloaded to. |
Example
Download the object object
from the container to the local path
file.txt
:
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
block.download_object_to_path(
from_path="object",
to_path="file.txt"
)
Source code in prefect_azure/blob_storage.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
get_directory(from_path=None, local_path=None)
async
Downloads the contents of a direry from the blob storage to a local path.
Used to enable flow code storage for deployments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_path
|
Optional[str]
|
The path of the directory in the blob storage. |
None
|
local_path
|
Optional[str]
|
The local path where the directory will be downloaded. |
None
|
Source code in prefect_azure/blob_storage.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
put_directory(local_path=None, to_path=None, ignore_file=None)
async
Uploads a directory to the blob storage.
Used to enable flow code storage for deployments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path
|
Optional[str]
|
The local path of the directory to upload. Defaults to current directory. |
None
|
to_path
|
Optional[str]
|
The destination path in the blob storage. Defaults to root directory. |
None
|
ignore_file
|
Optional[str]
|
The path to a file containing patterns to ignore during upload. |
None
|
Source code in prefect_azure/blob_storage.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
|
read_path(path)
async
Reads the contents of a file at the specified path and returns it as bytes.
Used to enable results storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path of the file to read. |
required |
Returns:
Type | Description |
---|---|
bytes
|
The contents of the file as bytes. |
Source code in prefect_azure/blob_storage.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
|
upload_from_file_object(from_file_object, to_path, **upload_kwargs)
async
Uploads an object from a file object to the specified path in the blob storage container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_file_object
|
BinaryIO
|
The file object to upload. |
required |
to_path
|
str
|
The path in the blob storage container to upload the object to. |
required |
**upload_kwargs
|
Dict[str, Any]
|
Additional keyword arguments to pass to the upload_blob method. |
{}
|
Returns:
Type | Description |
---|---|
Coroutine[Any, Any, str]
|
The path where the object was uploaded to. |
Example
Upload a file object to the container at the path object
:
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
with open("file.txt", "rb") as f:
block.upload_from_file_object(
from_file_object=f,
to_path="object"
)
Source code in prefect_azure/blob_storage.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
upload_from_folder(from_folder, to_folder, **upload_kwargs)
async
Uploads files from a local folder to a specified folder in the Azure Blob Storage container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_folder
|
Union[str, Path]
|
The path to the local folder containing the files to upload. |
required |
to_folder
|
str
|
The destination folder in the Azure Blob Storage container. |
required |
**upload_kwargs
|
Dict[str, Any]
|
Additional keyword arguments to pass to the
|
{}
|
Returns:
Type | Description |
---|---|
Coroutine[Any, Any, str]
|
The full path of the destination folder in the container. |
Example
Upload the contents of the local folder local_folder
to the container
folder folder
:
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
block.upload_from_folder(
from_folder="local_folder",
to_folder="folder"
)
Source code in prefect_azure/blob_storage.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
|
upload_from_path(from_path, to_path, **upload_kwargs)
async
Uploads an object from a local path to the specified destination path in the blob storage container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_path
|
Union[str, Path]
|
The local path of the object to upload. |
required |
to_path
|
str
|
The destination path in the blob storage container. |
required |
**upload_kwargs
|
Dict[str, Any]
|
Additional keyword arguments to pass to the
|
{}
|
Returns:
Type | Description |
---|---|
Coroutine[Any, Any, str]
|
The destination path in the blob storage container. |
Example
Upload a file from the local path file.txt
to the container
at the path object
:
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
block.upload_from_path(
from_path="file.txt",
to_path="object"
)
Source code in prefect_azure/blob_storage.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
write_path(path, content)
async
Writes the content to the specified path in the blob storage.
Used to enable results storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path where the content will be written. |
required |
content
|
bytes
|
The content to be written. |
required |
Source code in prefect_azure/blob_storage.py
695 696 697 698 699 700 701 702 703 704 705 706 |
|
AzureBlobStorageCredentials
Bases: Block
Stores credentials for authenticating with Azure Blob Storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
account_url
|
The URL for your Azure storage account. If provided, the account URL will be used to authenticate with the discovered default Azure credentials. |
required | |
connection_string
|
The connection string to your Azure storage account. If provided, the connection string will take precedence over the account URL. |
required |
Example
Load stored Azure Blob Storage credentials and retrieve a blob service client:
from prefect_azure import AzureBlobStorageCredentials
azure_credentials_block = AzureBlobStorageCredentials.load("BLOCK_NAME")
blob_service_client = azure_credentials_block.get_blob_client()
Source code in prefect_azure/credentials.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
check_connection_string_or_account_url(values)
classmethod
Checks that either a connection string or account URL is provided, not both.
Source code in prefect_azure/credentials.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
get_blob_client(container, blob)
Returns an authenticated Blob client that can be used to download and upload blobs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container
|
Name of the Blob Storage container to retrieve from. |
required | |
blob
|
Name of the blob within this container to retrieve. |
required |
Example
Create an authorized Blob session
import os
import asyncio
from prefect import flow
from prefect_azure import AzureBlobStorageCredentials
@flow
async def example_get_blob_client_flow():
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
azure_credentials = AzureBlobStorageCredentials(
connection_string=connection_string,
)
async with azure_credentials.get_blob_client(
"container", "blob"
) as blob_client:
# run other code here
pass
asyncio.run(example_get_blob_client_flow())
Source code in prefect_azure/credentials.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
get_client()
Returns an authenticated base Blob Service client that can be used to create other clients for Azure services.
Example
Create an authorized Blob Service session
import os
import asyncio
from prefect import flow
from prefect_azure import AzureBlobStorageCredentials
@flow
async def example_get_client_flow():
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
azure_credentials = AzureBlobStorageCredentials(
connection_string=connection_string,
)
async with azure_credentials.get_client() as blob_service_client:
# run other code here
pass
asyncio.run(example_get_client_flow())
Source code in prefect_azure/credentials.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
get_container_client(container)
Returns an authenticated Container client that can be used to create clients for Azure services.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container
|
Name of the Blob Storage container to retrieve from. |
required |
Example
Create an authorized Container session
import os
import asyncio
from prefect import flow
from prefect_azure import AzureBlobStorageCredentials
@flow
async def example_get_container_client_flow():
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
azure_credentials = AzureBlobStorageCredentials(
connection_string=connection_string,
)
async with azure_credentials.get_container_client(
"container"
) as container_client:
# run other code here
pass
asyncio.run(example_get_container_client_flow())
Source code in prefect_azure/credentials.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
AzureContainerInstanceCredentials
Bases: Block
Block used to manage Azure Container Instances authentication. Stores Azure Service Principal authentication data.
Source code in prefect_azure/credentials.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
|
get_container_client(subscription_id)
Creates an Azure Container Instances client initialized with data from this block's fields and a provided Azure subscription ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subscription_id
|
str
|
A valid Azure subscription ID. |
required |
Returns:
Type | Description |
---|---|
An initialized |
Source code in prefect_azure/credentials.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
|
get_resource_client(subscription_id)
Creates an Azure resource management client initialized with data from this block's fields and a provided Azure subscription ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subscription_id
|
str
|
A valid Azure subscription ID. |
required |
Returns:
Type | Description |
---|---|
An initialized |
Source code in prefect_azure/credentials.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
|
validate_credential_kwargs(values)
classmethod
Validates that if any of client_id
, tenant_id
, or client_secret
are
provided, all must be provided.
Source code in prefect_azure/credentials.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
|
AzureContainerWorker
Bases: BaseWorker
A Prefect worker that runs flows in an Azure Container Instance.
Source code in prefect_azure/workers/container_instance.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 |
|
run(flow_run, configuration, task_status=None)
async
Run a flow in an Azure Container Instance. Args: flow_run: The flow run to run. configuration: The configuration for the flow run. task_status: The task status object for the current task. Used to provide an identifier that can be used to cancel the task.
Returns:
Type | Description |
---|---|
The result of the flow run. |
Source code in prefect_azure/workers/container_instance.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
AzureCosmosDbCredentials
Bases: Block
Block used to manage Cosmos DB authentication with Azure.
Azure authentication is handled via the azure
module through
a connection string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection_string
|
Includes the authorization information required. |
required |
Example
Load stored Azure Cosmos DB credentials:
from prefect_azure import AzureCosmosDbCredentials
azure_credentials_block = AzureCosmosDbCredentials.load("BLOCK_NAME")
Source code in prefect_azure/credentials.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
get_client()
Returns an authenticated Cosmos client that can be used to create other clients for Azure services.
Example
Create an authorized Cosmos session
import os
from prefect import flow
from prefect_azure import AzureCosmosDbCredentials
@flow
def example_get_client_flow():
connection_string = os.getenv("AZURE_COSMOS_CONNECTION_STRING")
azure_credentials = AzureCosmosDbCredentials(
connection_string=connection_string,
)
cosmos_client = azure_credentials.get_client()
return cosmos_client
example_get_client_flow()
Source code in prefect_azure/credentials.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
get_container_client(container, database)
Returns an authenticated Container client used for querying.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container
|
str
|
Name of the Cosmos DB container to retrieve from. |
required |
database
|
str
|
Name of the Cosmos DB database. |
required |
Example
Create an authorized Container session
import os
from prefect import flow
from prefect_azure import AzureBlobStorageCredentials
@flow
def example_get_container_client_flow():
connection_string = os.getenv("AZURE_COSMOS_CONNECTION_STRING")
azure_credentials = AzureCosmosDbCredentials(
connection_string=connection_string,
)
container_client = azure_credentials.get_container_client(container)
return container_client
example_get_container_client_flow()
Source code in prefect_azure/credentials.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
get_database_client(database)
Returns an authenticated Database client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database
|
str
|
Name of the database. |
required |
Example
Create an authorized Cosmos session
import os
from prefect import flow
from prefect_azure import AzureCosmosDbCredentials
@flow
def example_get_client_flow():
connection_string = os.getenv("AZURE_COSMOS_CONNECTION_STRING")
azure_credentials = AzureCosmosDbCredentials(
connection_string=connection_string,
)
cosmos_client = azure_credentials.get_database_client()
return cosmos_client
example_get_database_client_flow()
Source code in prefect_azure/credentials.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
AzureMlCredentials
Bases: Block
Block used to manage authentication with AzureML. Azure authentication is
handled via the azure
module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tenant_id
|
The active directory tenant that the service identity belongs to. |
required | |
service_principal_id
|
The service principal ID. |
required | |
service_principal_password
|
The service principal password/key. |
required | |
subscription_id
|
The Azure subscription ID containing the workspace. |
required | |
resource_group
|
The resource group containing the workspace. |
required | |
workspace_name
|
The existing workspace name. |
required |
Example
Load stored AzureML credentials:
from prefect_azure import AzureMlCredentials
azure_ml_credentials_block = AzureMlCredentials.load("BLOCK_NAME")
Source code in prefect_azure/credentials.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
get_workspace()
Returns an authenticated base Workspace that can be used in Azure's Datasets and Datastores.
Example
Create an authorized workspace
import os
from prefect import flow
from prefect_azure import AzureMlCredentials
@flow
def example_get_workspace_flow():
azure_credentials = AzureMlCredentials(
tenant_id="tenant_id",
service_principal_id="service_principal_id",
service_principal_password="service_principal_password",
subscription_id="subscription_id",
resource_group="resource_group",
workspace_name="workspace_name"
)
workspace_client = azure_credentials.get_workspace()
return workspace_client
example_get_workspace_flow()
Source code in prefect_azure/credentials.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|