Back to all reviewers

Consistent method interfaces

boto/boto3
Based on 5 comments
Python

Design APIs with consistent method interfaces across related resources to improve usability and reduce learning curve. When similar operations are available on different resources, they should follow the same naming conventions, parameter structures, and behavior patterns.

API Python

Reviewer Prompt

Design APIs with consistent method interfaces across related resources to improve usability and reduce learning curve. When similar operations are available on different resources, they should follow the same naming conventions, parameter structures, and behavior patterns.

Key principles:

  1. Mirror common operations across resources: When a method makes sense for multiple resource types, provide it consistently. For example, if users can upload files to S3 objects via client.upload_file(), they should also be able to do it via bucket.upload_file() with consistent parameters.

  2. Handle parameters consistently: Use the same parameter names and structures for similar operations. If ExtraArgs is used in one method to pass additional options, use it consistently in related methods.

# Example of consistent method interfaces across resources
# Client-level method
s3.meta.client.upload_file('filename.txt', 'bucket-name', 'key')

# Same method available at bucket level with identical parameter structure
bucket = s3.Bucket('bucket-name')
bucket.upload_file('filename.txt', 'key')
  1. Consider cross-resource operations: When designing methods that operate across resources (like copying between buckets), carefully consider authentication needs and parameter mapping between underlying API calls.

  2. Provide appropriate configuration options: Allow users to customize behavior through configuration objects that can be reused across operations and applied consistently.

  3. Document parameter behavior: Clearly document how parameters map to underlying operations, especially when a high-level method may call multiple lower-level operations with different parameter requirements.

Following these principles results in intuitive APIs where users can confidently apply knowledge from one part of the API to another, reducing friction and improving developer productivity.

5
Comments Analyzed
Python
Primary Language
API
Category

Source Discussions