
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

2K+ Views
Problem Statement − Use boto3 library in Python to download an object from S3 at a given local path/default path with overwrite existing file as true. For example, download test.zip from Bucket_1/testfolder of S3.Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − From pathlib, import Path to check filenameStep 3 − s3_path, localpath and overwrite_existing_file are the three parameters in the function download_object_from_s3Step 4 − Validate the s3_path is passed in AWS format as s3://bucket_name/key. By default, localpath = None and overwrite_existing_file = True. User can pass these values as well to ... Read More

851 Views
Problem Statement − Use Boto3 library in Python to upload an object into S3. For example, how to upload test.zip into Bucket_1 of S3.Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − From pathlib, import PurePosixPath to retrive filename from pathStep 3 − s3_path and filepath are the two parameters in function upload_object_into_s3Step 4 − Validate the s3_path is passed in AWS format as s3://bucket_name/key and filepath as local path C://users/filenameStep 5 − Create an AWS session using boto3 library.Step 6 − Create an AWS resource for S3.Step 7 − Split the ... Read More

510 Views
Problem Statement − Use Boto3 library in Python to determine whether a root bucket exists in S3 or not.Example − Bucket_1 exists or not in S3.Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using boto3 library.Step 3 − Create an AWS client for S3.Step 4 − Use the function head_bucket(). It returns 200 OK if the bucket exists and the user has permission to access it. Otherwise, the response would be 403 Forbidden or 404 Not Found.Step 5 − Handle the exception based on the response code.Step ... Read More

2K+ Views
Problem Statement − Use Boto3 library in Python to determine whether a root bucket exists in S3 or not.Example − Bucket_1 exists or not in S3.Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using boto3 library.Step 3 − Create an AWS resource for S3.Step 4 − Use the function head_bucket(). It returns 200 OK if the bucket exists and the user has permission to access it. Otherwise, the response would be 403 Forbidden or 404 Not Found.Step 5 − Handle the exception based on the response code.Step 6 ... Read More

7K+ Views
Problem Statement − Use Boto3 library in Python to get the list of all buckets present in AWSExample − Get the name of buckets like – BUCKET_1, BUCKET2, BUCKET_3Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using Boto3 library.Step 3 − Create an AWS client for S3.Step 4 − Use the function list_buckets() to store all the properties of buckets in a dictionary like ResponseMetadata, bucketsStep 5 − Use for loop to get only bucket-specific details from the dictionary like Name, Creation Date, etc.Step 6 − Now, retrieve ... Read More

407 Views
Problem Statement − Use boto3 library in Python to get the list of all buckets present in AWS.Example − Get the name of buckets like – BUCKET_1, BUCKET2, BUCKET_3Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using Boto3 library.Step 3 − Create an AWS resource for S3Step 4 − Use the function buckets.all() to list out the bucket names.Step 5 − Handle any unwanted exception, if it occursStep 6 − Return the list of buckets_namevExampleThe following code gets the list of buckets present in S3 −import boto3 ... Read More

755 Views
In this article, we will see how you can use Boto3 library in Python to connect with different AWS services.ExampleConnect with AWS S3.Connect with AWS Glue JobConnect with AWS SQS and many more.Approach/Algorithm to solve this problemStep 1 − Create an AWS session using Boto3 library.Step 2 − Pass the AWS service name in client to get a low-level service access.Or, pass the AWS service name in resource to get high-level object-oriented service access/highlevel interface.ExampleThe following code connects with different AWS services −import boto3 # To get AWS Client def getconnection_AWSClient(service_name): session = boto3.session.Session() # User can pass ... Read More

5K+ Views
When a user wants to use AWS services using lambda or programming code, a session needs to set up first to access AWS services.An AWS session could be default as well as customized based on needs.Problem Statement − Use Boto3 library in Python to create an AWS session.Approach/Algorithm to solve this problemStep 1 − To create an AWS session, first set up authentication credentials. Users can find it in IAM console or alternatively, create the credential file manually. By default, its location is at ~/.aws/credentialsExample[default] aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_SECRET_ACCESS_KEY aws_session_token = YOUR_SESSION_TOKEN region = REGION_NAMEStep 2 − Install ... Read More

817 Views
In this program, we will calculate the rms (root mean square) of all the pixels in each channel using the Pillow library. There are a total three channels in an image and therefore, we will get a list of three values.Original ImageAlgorithmStep 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the root mean square of the pixels.Example Codefrom PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.rms)Output[104.86876722259062, 96.13661429330132, 91.8480515464677]

1K+ Views
In this program, we will calculate the variance of all the pixels in each channel using the Pillow library. There are a total three channels in an image and therefore, we will get a list of three values.Original ImageAlgorithmStep 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the variance of the pixels.Example Codefrom PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.var)Output[5221.066590958682, 4388.697801428673, 4291.257706548981]