Use of service with Python

Library Installation

To install the Python library for this version that allows connection to the OpenCayle service, run:

pip install boto3

If you need more information on how to use this library: https://boto3.amazonaws.com/v1/documentation/api/1.35.29/guide/quickstart.html


Establishing the Connection with the Server

To establish the connection with the OpenCAYLE server from a Python script, you will need to configure the following parameters as shown in the example below. If you do not have the indicated AccessKey, follow these steps to obtain the AccessKey.

s3 = boto3.resource('s3',
    endpoint_url='https://ss3.scayle.es:443',
    aws_access_key_id='AccessKey',  
    aws_secret_access_key='AccessKey',
    config=Config(signature_version='s3v4')
)

Bucket Management

To create a bucket, complete the following parameters:

  • BucketName: The name of the bucket in OpenCAYLE where the file is located. Example: resultados_01
s3.create_bucket(
    Bucket="BucketName"
)

To list the buckets associated with your account:

for bucket in s3.buckets.all():
    print(bucket.name)

File Management

To upload files to a bucket, complete the following parameters:

  • PathOrigen: Directory where the file is located in the bucket. Example: /home/user/Desktop/medicion_01.txt
  • BucketName: Name of the bucket in OpenCAYLE where the file is located. Example: datos_tiempo_madrid
  • PathDestino: Directory on the computer where the file will be saved. Example: /2024/marzo/medicion_01.txt
with open('PathOrigen', 'rb') as data:
    s3.Bucket('BucketName').put_object(Key='PathDestino', Body=data)

To download files from a bucket, complete the following parameters:

  • BucketName: Name of the bucket in OpenCAYLE where the file is located. Example: datos_leon_2023
  • PathOrigen: Directory where the file is located in the bucket. Example: /enero/semana1/prediccion_01.txt
  • PathDestino: Directory on the computer where the file will be saved. Example: /home/user/Downloads/prediccion_01.txt
s3.Bucket('BucketName').download_file('PathOrigen', 'PathDestino')

Last updated: 24/02/2025 11:37