You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DISCUSSION: Switch to apitools as a dependency #755
using apitools is two steps: first, create a client, and second, load that code, then instantiate and call.
from scratch:
(sample)[~/t/storage_example] $ pip install google-apitools[cli]
... <installing> ...
(sample)[~/t/storage_example] $ gen_client --discovery_url=storage.v1 --nogenerate_cli --outdir=storage client
(sample)[~/t/storage_example] $ l
total 0
0 storage/
(sample)[~/t/storage_example] $ cd storage/
(sample)[~/t/storage_example/storage] $ l
total 120
4 __init__.py 44 storage_v1_client.py 72 storage_v1_messages.py
(sample)[~/t/storage_example/storage] $ python
Python 2.7.9 (default, Jan 8 2015, 10:14:19)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import apitools.base.py as apitools_base
>>> import storage_v1_client as storage_client
>>> import storage_v1_messages as storage_messages
>>> client = storage_client.StorageV1()
>>> client.buckets.List(storage_messages.StorageBucketsListRequest(project='google.com:apitools'))
<Buckets
items: [<Bucket
... copious output ...
kind: u'storage#buckets'>
>>> buckets = _
>>> [bucket.name for bucket in buckets.items]
['apitools', ... <a zillion other buckets> ..., 'apitools-public']
>>> import StringIO
>>> upload = apitools_base.Upload.FromStream(StringIO.StringIO('hello world\n'), mime_type='text/plain')
>>> request = storage_messages.StorageObjectsInsertRequest()
>>> request.bucket = 'apitools'
>>> request.name = 'test_object'
>>> client.objects.Insert(request, upload=upload)
<new object metadata comes back>
>>> client.objects.Get(storage_messages.StorageObjectsGetRequest(bucket='apitools', object='test_object'), download=apitools_base.Download.FromFile('important.txt'))
Received bytes 0-11/12
Download complete
>>>
(sample)[~/t/storage_example/storage] $ cat important.txt
hello world
(sample)[~/t/storage_example/storage] $
there's plenty more in there -- i'm happy to do a little demo, if there's interest.
for compatibility, there are really three questions: generated clients, generated CLIs, and the gen_client tool itself. you should only care about the first, and eventually the third.
the first should already work in py3, or if not, i want to fix it. generated CLIs are furthest out, because it involves changing the codegen to not use gflags/apputils, but i don't think you care right now. for gen_client, it's actually a quick fix (where i plan to clean up 1-2 other small things), but i'm short on time (cf the long response on this! 😏)
sure -- thursday would be best for me, but we can coordinate by email. some offhand answers:
for auth, you can either let apitools do it, or just pass a valid oauth2client.Credentials object as the credentials argument to the constructor, and it'll use those credentials.
multipart and resumable are both handled for you; we choose a default based on size, but you can change it on the Upload/Download instance as desired.
batching works fine (though, as discussed, not with media).
@craigcitro RE: "(though, as discussed, not with media)." When did we discuss? Link? Media here means any files (i.e. non-metadata) at all or "media uploads"? Is it just a missing feature of the library or not supported by the backend?
media means anything involving upload/download of files. apitools doesn't support it (and throws an appropriate error, i believe), but there's no support on the backend.
Overarching theme here: what implicit magic do I need to worry about to turn off?
Secondary to all this, is I noticed a big fat
Generating new OAuth credentials ...
WARNING:root:This function, oauth2client.tools.run(), and the use of the gflags library are deprecated and will be removed in a future version of the library.
Go to the following link in your browser:
if you use a generated client, that all goes away. you'll just pass an upload with the request, and (if you set auto_transfer=False) call StreamInChunks afterwards.
Activity
dhermes commentedon Mar 24, 2015
I've tentatively started to test how
python3-ready theapitoolscodebase is and haven't had much luck.I couldn't even get
toxto run: google/apitools#4In addition, it seems there are some Python 2 specific imports, for example the
StringIOmodule is used.dhermes commentedon Mar 31, 2015
@craigcitro Can we chat about this?
dhermes commentedon Mar 31, 2015
@craigcitro Can you provide a snippet or two for
craigcitro commentedon Apr 4, 2015
from scratch:
there's plenty more in there -- i'm happy to do a little demo, if there's interest.
gen_clienttool itself. you should only care about the first, and eventually the third.the first should already work in py3, or if not, i want to fix it. generated CLIs are furthest out, because it involves changing the codegen to not use gflags/apputils, but i don't think you care right now. for
gen_client, it's actually a quick fix (where i plan to clean up 1-2 other small things), but i'm short on time (cf the long response on this! 😏)dhermes commentedon Apr 6, 2015
@craigcitro I'll take you up on that demo.
It seems the thorniest parts will be
craigcitro commentedon Apr 6, 2015
sure -- thursday would be best for me, but we can coordinate by email. some offhand answers:
oauth2client.Credentialsobject as thecredentialsargument to the constructor, and it'll use those credentials.Upload/Downloadinstance as desired.dhermes commentedon Apr 7, 2015
@craigcitro RE: "(though, as discussed, not with media)." When did we discuss? Link? Media here means any files (i.e. non-metadata) at all or "media uploads"? Is it just a missing feature of the library or not supported by the backend?
craigcitro commentedon Apr 7, 2015
@dhermes #654 (comment)
media means anything involving upload/download of files. apitools doesn't support it (and throws an appropriate error, i believe), but there's no support on the backend.
dhermes commentedon Apr 7, 2015
Thanks for the reference! It totally slipped my mind.
dhermes commentedon Apr 8, 2015
Two quick notes:
import apitools.base.py as apitools_baseis not instantaneous. Is there a way to disable whatever magic occurs?client = storage_client.StorageV1()tries to get implicit credentials. Issufficient to dodge this overhead?
Overarching theme here: what implicit magic do I need to worry about to turn off?
Secondary to all this, is I noticed a big fat
Is there a corresponding bug in the repo?
dhermes commentedon Apr 8, 2015
I filed google/apitools#14 to complain about start-up / import times in
apitools.7 remaining items
dhermes commentedon Apr 8, 2015
Saw the comment. Is the
transfer.RESUMABLE_UPLOADstuff necessary or can we rely onapitoolsto handle it?craigcitro commentedon Apr 8, 2015
if you use a generated client, that all goes away. you'll just pass an upload with the request, and (if you set
auto_transfer=False) callStreamInChunksafterwards.chore(deps): update all dependencies (#755)
chore: release 0.40.4 (#755)
chore(python): remove obsolete release scripts and config files (#755)
chore: add sync-repo-settings.yaml (#755)
chore(python): update release.sh to use keystore (#755)
fix(dependencies): add urllib3 and requests to aiohttp extra (#755)
chore(deps): update all dependencies (#755)
chore(deps): update dependency google-cloud-bigquery to v2.21.0 (#755)
chore(deps): update dependency google-cloud-spanner to v3.13.0 (#755)
chore(deps): update dependency protobuf to v6.32.1 (#755)
docs: migrate code from googleapis/python-bigquery (#18303)