Create SAS service using python

Chilakapati Jyothirmayi 0 Reputation points

In powerbi, Is it possible to create sas service for a blob using python?

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,836 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sudipta Chakraborty - MSFT 1,101 Reputation points Microsoft Employee

    @Chilakapati Jyothirmayi : You can create a SAS token using Python and use it in Power BI to connect to a Azure storage account. While configuring the data source in Power BI choose the Authentication kind as Shared Access Signature (SAS).

    The below mentioned code creates a SAS token that’s valid for one day and grants read access to the specified blob. Please replace blob_client and account_key with your actual blob client and account key.

    from import BlobServiceClient, BlobClient, BlobSasPermissions, generate_blob_sas
    import datetime
    def create_service_sas_blob(blob_client: BlobClient, account_key: str):
        # Create a SAS token that's valid for one day
        sas_token = generate_blob_sas(
            expiry=datetime.datetime.utcnow() + datetime.timedelta(days=1)
        return sas_token
    0 comments No comments

  2. Nehruji R 3,801 Reputation points Microsoft Vendor

    Hello Chilakapati Jyothirmayi,

    Greetings! Welcome to Microsoft Q&A Platform.

    Yes, In Power BI you can create a service Shared Access Signature (SAS) for Azure Blob Storage using Python. A shared access signature (SAS) enables you to grant limited access to containers and blobs in your storage account. When you create a SAS, you specify its constraints, including which Azure Storage resources a client is allowed to access, what permissions they have on those resources, and how long the SAS is valid.

    You can create a service SAS to delegate limited access to a blob resource using the following method:

    The storage account access key used to sign the SAS is passed to the method as the account_key argument. Allowed permissions are passed to the method as the permission argument, and are defined in the BlobSasPermissions class.

    The following code example shows how to create a service SAS with read permissions for a blob resource:

    def create_service_sas_blob(self, blob_client: BlobClient, account_key: str):
        # Create a SAS token that's valid for one day, as an example
        start_time =
        expiry_time = start_time + datetime.timedelta(days=1)
        sas_token = generate_blob_sas(
        return sas_token

    You can find more information on how to create a SAS service for a Blob using Python in the following links -,

    Hope this answer helps! Please let us know if you have any further queries. I’m happy to assist you further.

    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments