question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feedback] API is not really pythonic

See original GitHub issue

While I do understand the desire to provide methods very similar (if not analogous) to the AWS CLI, I really feel like working with boto3 does not really improve on the AWS CLI. From my point of view, boto3 should not only be a wrapper, but also an adapter to make the CLI something desirable to work with from python. For instance, instead of creating an S3 client with boto3.client('s3'), hide this and use a S3Client class. Instead of managing multi-part upload with the upload id directly, it would be more ‘pythonic’ to have a MultiPartUpload class, and have the corresponding methods take or return an instance of this class. What is the point of having the Client do operations such as get_bucket_policy(Bucket=‘string’)? Wouldn’t it be much better (and intuitive) to have a getter for bucket_policy on the Bucket class? Also, having helper methods would help a lot. Something like Bucket.upload_file(file, path), or along those lines. The point isn’t precisely the examples I have pointed out here, the point is the library is hard to work with, it is essentially the same as the CLI. Please note I do not mean any disrespect and this is just, at least from my point of view, constructive criticism.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:16
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
brianbruggemancommented, Feb 22, 2016

So something I was disappointed with recently.

$ python >>> x = boto3.resource(‘s3’) >>> x s3.ServiceResource >>> import s3 ImportError: … >>> type(x) boto3.resources.factory.s3.ServiceResource >>> isinstance(s3, boto3.resources.factory.s3.ServiceResource) AttributeError: ‘module’ object has no attribute ‘s3’

Every python API should be able to answer these questions:
“What exactly is this object I’m using?” “Where can I find the exact code for this object?” “How can I perform some basic operations on this object?”

4reactions
kyleknapcommented, May 8, 2015

@autrilla

Thank you for the feedback. We truly appreciate any feedback we can get on the project.

It is true that the Boto3 and the CLI share similar methods. This is because both of these projects are separate higher level layers to a lower level library that we maintain: botocore. Botocore is lower level in the sense that it methods are a near direct mapping to the various AWS API’s . There are very few customizations added to these methods, as they are added in the higher level libraries/tools such as Boto3 and the CLI.

I do have one question. Have you had a chance to look at the resource interface of boto3?

So boto3 has two different interfaces to interact with AWS’s APIs. There is the client interface that you mentioned. The client interface is pretty much the same interface used by botocore, where the methods are nearly direct mappings to the APIs. The main purpose of this interface is to allow users to make more fine-tuned requests to the APIs (i.e. you know exactly what parameters you want to a send in a request and you just want a dictionary back representing what was in the response).

The other interface, which sounds like the one you want is, the resource interface. The purpose of this interface is to make interaction more pythonic and object oriented when working with AWS. When you use resources, you are working with auto-generated classes that live onto of the client interface.

To hit some of the points you mentioned, the resource classes have getters (they are labeled as identifiers and attributes) that will actually make the underlying call for you to retrieve the necessary data. Resources also can create and return other resources to use from a method call, instead of just a dictionary. So for example an s3 Object resource object has the method initiate_multipart_upload that will return to you a s3 MultipartUpload resource object to work with a multipart upload. Then on top of these resources we have customizations that are built on top of AWS APIs that requires stringing together possiblly multiple API calls. For example, we recently added an upload_file and download_file method (note that this is only available from the client for now): https://boto3.readthedocs.org/en/latest/reference/customizations/s3.html

Please let us know if you have any follow up questions/comments/feedback/feature requests. We love getting feedback on how to improve this project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Comments in Python (Guide)
Learn how to write Python comments that are clean, concise, and useful. Quickly get up to speed on what the best practices are,...
Read more >
How to submit user feedback using Sentry api in Python?
The python script is CLI based, so I would like the user to be able to type the bug information straight into the...
Read more >
Python Rest APIs: 5 Important Commands, Key Modules, and ...
A Python REST API should not rely on data saved on the server or sessions to ... such as the API key, access...
Read more >
Python API Tutorial: Getting Started with APIs - Dataquest
401 : The server thinks you're not authenticated. Many APIs require login ccredentials, so this happens when you don't send the right ...
Read more >
How to Build a Python REST API Server for Quick Mocking
There are many ways you can stub out your APIs in Python. Creating python APIs, includes the same examples in two frameworks, so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found