I'm using Python 3.8 and Azure data lake Gen 2. I want to set an expiration time for a file I save on the data lake. Following this -- azure.datalake.store.core.AzureDLFileSystem class | Microsoft Docs, I tried the below
file_client = directory_client.create_file(filename)
file_client.upload_data(
data,
overwrite=True
)
ts = time.time() + 100
file_client.set_expiry(path=path, expire_time=ts)
but am getting the error
AttributeError: 'DataLakeFileClient' object has no attribute 'set_expiry'
What's the proper way to set an expiration time when creating a file on the data lake?
The reason for your error, is that you appear to be attempting to call a method belonging to
azure.datalake.store.core.AzureDLFileSystemon an object of typeDataLakeFileClient. This is why you get the error! The method does not exist for objects of typeDataLakeFileClient.If you wish to call the method for set_expiry, you must first create the correct kind of object.
For example in Gen1, create the object first as described here:
https://learn.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-python
Using this object, you can call
adlsFileSystemClient exactly like how you have in your code example.
Just make sure you're trying to call methods on the correct type of object.
For Gen 2:
For Gen2, you need to set a blob to expire as follows: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-lifecycle-management-concepts?tabs=azure-portal#expire-data-based-on-age
Expire data based on age