jeshan / botostubs Goto Github PK
View Code? Open in Web Editor NEWboto3 code assistance for any API in any IDE, always up to date
License: Other
boto3 code assistance for any API in any IDE, always up to date
License: Other
As of python 3.6, type hints have changed from
client = boto3.client('ssm') # type: botostubs.SSM
to
client: botostubs.SSM = boto3.client('ssm')
and I can't get it to work in VS code. I never used it in python 3.5 so I'm not sure if the new type hints are the issue or it's just not working with my vscode for some other reason, but I wanted to rule out the type hint format change.
$ pip list
Package Version
--------------- ------------
ansible 2.9.12
awscli 1.18.116
boto3 1.14.39
botocore 1.17.39
botostubs 0.12.1.14.38
cffi 1.14.1
colorama 0.4.3
cryptography 3.0
docutils 0.15.2
Jinja2 2.11.2
jmespath 0.10.0
MarkupSafe 1.1.1
pip 20.2.1
pyasn1 0.4.8
pycparser 2.20
python-dateutil 2.8.1
PyYAML 5.3.1
rsa 4.5
s3transfer 0.3.3
setuptools 28.8.0
six 1.15.0
urllib3 1.25.10
wheel 0.34.2
$ python
Python 3.5.9 (default, Jul 6 2020, 09:15:33)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import botostubs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.envs/python3_5/lib/python3.5/site-packages/botostubs/__init__.py", line 15824
stack_id: str=None
^
SyntaxError: invalid syntax
works just fine with Python 3.6
I would like to add resources like VPC
etc.
Not sure the level of effort to get this to work with mypy. I have many examples but this one makes the most sense:
Making API call with filter:
response = client.describe_instance_type_offerings(
LocationType=location,
Filters=[{"Name": "instance-type", "Values": [instance_type]}],
)
mypy error:
error: List item 0 has incompatible type "Dict[str, Sequence[str]]"; expected "Filter" [list-item]
I have tried many ways to fix it:
filter: botostubs.EC2.Filter = {
"Name": "instance-type",
"Values": [instance_type]
}
but nothing works. Thats because the variable filter
is supposed to be an instance of the class Filter
. Where really with boto3 a filter is a Dict[str, Any]
.
I haven't even looked at what it would take to implement but I might give this a look if this is something people are interested in.
look into better visual studio code integration, without requiring explicit type hinting. Maybe now with pylance extension, where stubs can be stored in a directory, and used from there, maybe that will help. so we don't have to add type hints to get auto-complete/hover working. See here: https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance
Hi!
I'm using botostubs to facilitate learning in the boto3 API.
While using it, I tested a code provided by the boto3 documentation itself and had the following error:
Any attempt to use exceptions with s3 botostubs fails.
Am I doing something wrong?
Here is the code:
import boto3
import botostubs
s3 = boto3.client('s3') #type: botostubs.S3
try:
s3.create_bucket(Bucket='sdkpython')
except s3.meta.client.exceptions.BucketAlreadyExists as err:
print("Bucket already exists!".format(err.response['Error']['Bucket']))
raise err
Thanks!
Thanks again for this great package!
From: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#bucket we know these are the resource's available collections:
multipart_uploads
object_versions
objects
I was hoping/expecting these to be listed...have I misunderstood the scope of this package?
botostubs type hinting, hover for get_paginator works fine. hover over "list_policies" doesn't work. autocomplete where "list_policies" doesn't work. It be nice if botostubs can be updated to handle things, when we have to use pagination.
`
import boto3
import botostubs
org_client = boto3.client("organizations") # type: botostubs.Organizations
def get_policies(filter):
paginator = org_client.get_paginator("list_policies")
policies = []
for page in paginator.paginate(Filter=filter):
policies.extend(page.get("Policies"))
return policies
`
Hi Jeshan
Thanks for developing botostubs. its very useful tool. Delighted to hear about your journey in making this tool. its very exciting. Installed botostubs on my ubuntu. Its working for client but not for Resource object
obj = boto3.resource('s3') # type : botostubs.ResourceS3
so hear if type .(dot) after obj its not showing the properties.
For Client API you are using type like below, is there any analogy? or where will i find which type to use ?
s3 = boto3.client('s3') # type: botostubs.S3
once again thanks for building the tool and showing how to use AWS services end to end.
Regards
swanand
Hi Jeshan
thanks for developing this tool. its very useful.
I am new to aws and wants to do programming.But I am stuck here. when botostubs
is installed and checked it started working for the example you have shown.
s3 = boto3.client('s3') # type: botostubs.S3
s3 properties are shown. no issue.
But when I exit from the vscode and come back again then all things disappear and auto complete doesn't work. This is consistently happening sometimes it works other don't.
what I observed is that, If i import 'sys' or 'os' package and then used 'sys.path.append()' using
autocomplete feature of vs code then invoked s3. autocomplete then it start displaying properties. But behavior is not consistent. its very frustrating.
now I also want to create object for dynamodb , I am using below command but its not showing the properties.
dynamo = boto3.client('dynamodb') # type: botostubs.Dynamodb
dynamo = boto3.client('dynamodb') # type: botostubs.DYNAMODB
so I don't know if problem is with type definition .
I think 'type :' is very important here otherwise it won't show property. do you have complete list of types for each aws object? so that no guessing.
Also in your video, you have shown when you type # type : , you automatically gets "botostubs" and subsequent property, how to get that? Its not working on my end.
Your help is highly appreciated.
Regards
swanand
First, thank you for your work on this package as the lack of type information in boto3 has been a huge annoyance, although I had a little difficulty getting it to work in PyCharm.
After installing the package from PyPI, neither type annotations or type comments were having any affect. It turns out however that PyCharm was not indexing the botostubs package because the __init__.py
file was too large as explained when I opened it and an error message was shown:
File size exceeds configured limit, code insight features not available
I was able to increase this limit under Help -> Edit Custom Properties by adding idea.max.intellisense.filesize=999999
and restarting PyCharm, which made the type annotations work as expected.
Perhaps this should be added to the README
?
The data generated by the botostubs library doesn't appear to include information on data types used by the Resource
classes - created by boto3.resource
.
is there a list of botostubs enum values? I cannot find the correct ENUM for kafka. Autocomplete on the type is not working. I found S3 from example.
def s3_client():
s3 = boto3.client("s3") # type: botostubs.S3
return s3 <-- THIS WORKS
def msk_client():
msk = boto3.client("kafka") # type: botostubs.KAFKA
return msk <-- THIS DOES NOT WORK
I created a S3 bucket ressource with the boto3 library and annotated it with type hints.
From the S3 resource i generated an bucket object.
The auto-completion does seem to work just fine, apart from the methods upload_file[obj]()
and download_file[obj]()
, which is simply not existent on the bucket object:
Here is the documentation of this method.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html?highlight=upload_file#S3.Bucket.upload_fileobj
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.