LakeFS Presigned URL example
public
Mar 25, 2025
Never
31
1 import time 2 import lakefs_client 3 from lakefs_client.api import objects_api 4 from lakefs_client.model.error import Error 5 from pprint import pprint 6 # Defining the host is optional and defaults to http://localhost/api/v1 7 # See configuration.py for a list of all supported configuration parameters. 8 configuration = lakefs_client.Configuration( 9 host = "http://localhost/api/v1" 10 ) 11 12 # The client must configure the authentication and authorization parameters 13 # in accordance with the API server security policy. 14 # Examples for each auth method are provided below, use the example that 15 # satisfies your auth use case. 16 17 # Configure HTTP basic authorization: basic_auth 18 configuration = lakefs_client.Configuration( 19 username = 'YOUR_USERNAME', 20 password = 'YOUR_PASSWORD' 21 ) 22 23 # Configure API key authorization: cookie_auth 24 configuration.api_key['cookie_auth'] = 'YOUR_API_KEY' 25 26 # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed 27 # configuration.api_key_prefix['cookie_auth'] = 'Bearer' 28 29 # Configure Bearer authorization (JWT): jwt_token 30 configuration = lakefs_client.Configuration( 31 access_token = 'YOUR_BEARER_TOKEN' 32 ) 33 34 # Configure API key authorization: oidc_auth 35 configuration.api_key['oidc_auth'] = 'YOUR_API_KEY' 36 37 # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed 38 # configuration.api_key_prefix['oidc_auth'] = 'Bearer' 39 40 # Configure API key authorization: saml_auth 41 configuration.api_key['saml_auth'] = 'YOUR_API_KEY' 42 43 # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed 44 # configuration.api_key_prefix['saml_auth'] = 'Bearer' 45 46 # Enter a context with an instance of the API client 47 with lakefs_client.ApiClient(configuration) as api_client: 48 # Create an instance of the API class 49 api_instance = objects_api.ObjectsApi(api_client) 50 repository = "repository_example" # str | 51 ref = "ref_example" # str | a reference (could be either a branch or a commit ID) 52 path = "path_example" # str | relative to the ref 53 range = "bytes=0-1023" # str | Byte range to retrieve (optional) 54 if_none_match = "33a64df551425fcc55e4d42a148795d9f25f89d4" # str | Returns response only if the object does not have a matching ETag (optional) 55 presign = True # bool | (optional) 56 57 # example passing only required values which don't have defaults set 58 try: 59 # get object content 60 api_response = api_instance.get_object(repository, ref, path) 61 pprint(api_response) 62 except lakefs_client.ApiException as e: 63 print("Exception when calling ObjectsApi->get_object: %s\n" % e) 64 65 # example passing only required values which don't have defaults set 66 # and optional values 67 try: 68 # get object content 69 api_response = api_instance.get_object(repository, ref, path, range=range, if_none_match=if_none_match, presign=presign) 70 pprint(api_response) 71 except lakefs_client.ApiException as e: 72 print("Exception when calling ObjectsApi->get_object: %s\n" % e)