Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm intellisense for boto3

Tags:

having problems seeing full intellisense (code completion) options in PyCharm. working with python 3.4 on Windows. the suggests are partially working:

import boto3 s = boto3.Session()  (boto3. will bring up list of methods/params of object boto3) ec2 = s.resource('ec2') (resource is a suggested method!) ec2. <<<< this brings up nothing. For some reason PyCharm cant detect that ec2 object would have  

while I can work off documentation alone, intellisense is just such a nice feature to have!

ive had similar problems getting it to complete lxml syntax but I thought that was because I had to install lxml directly as a binary (too many hoops to jump through on windows to install it via pip)

Anyone else encounter similar problems?

While we are here, I see a lot of different libraries around using awscli with python: boto, boto3, troposphere etc. What are some advantages of using one over the other. Amazon states that boto3 is the prefered method over boto but for my usage of starting/stopping ec2 instances could be easily done with older boto.

like image 523
Alex C Avatar asked Jul 22 '15 06:07

Alex C


People also ask

What is pyboto3?

pyboto3 interface stubsPythonic Interface for AWS boto3 that gives you autocomplete on all AWS services. The code is not to be imported. you can only use it as a typehint for autocomplete in pycharm. This package will minimize the time you have to look for AWS documentation online.


2 Answers

I was frustrated with the same issue. So I decided to parse boto3 documentation and generate wrapper classes from the documentation. Here is the link to project https://github.com/gehadshaat/pyboto3

To install it

pip install pyboto3 

To use it

import boto3 s3 = boto3.client('s3') """ :type : pyboto3.s3 """ # s3. -> will give you autocomplete for s3 methods in pycharm 

Make sure that you first:

  1. Install pyboto3 -> pip install pyboto3 | pip3.x install pyboto3
  2. Check your interpreter settings and verify that you see pyboto3 on the list
  3. Do a File -> Invalidate Caches/Restart

After Pycharm restarts you should see intellisense working in your favor and all of the available methods for the service (in the case above s3) you are trying to use available to you!

like image 139
gehad Avatar answered Sep 23 '22 07:09

gehad


This is happening because all of the methods on the boto3 clients and resource objects are generated at runtime based on a JSON file that describes what operations the service supports. Pycharm would have to have specific knowledge about this process in order to auto complete method names.

For your second question, boto3 is the official AWS SDK for Python. One of the main advantages of boto3 is that because of this JSON model driven process that describes the AWS APIs, most new service features only require a simple model update. This means API updates happen in a quick, consistent, and reliable manner.

But if you're using boto in existing code and it's working for you, feel free to keep using it. You can always install boto3 along side boto if you need to pull in new functionality.

like image 31
jamesls Avatar answered Sep 24 '22 07:09

jamesls