Open API specification and App Engine Endpoints - python

I have developed an API on App Engine using the endpoints-proto-datastore library. At this point I am exploring the use of Swagger to create an Endpoints specification, and am not sure how to proceed. Support for this is indicated in Google's Endpoints docs, but there's not much to get started, particularly for Python.
If possible, I'd like to continue using just the endpoints library and webapp rather than going to Flask which seems like overkill. Any hints for how one might thus proceed?

Related

How to create a Python API and use it with React Native?

I'm learning about basic back-end and server mechanics and how to connect it with the front end of an app. More specifically, I want to create a React Native app and connect it to a database using Python(simply because Python is easy to write and fast). From my research I've determined I'll need to make an API that communicates via HTTP with the server, then use the API with React Native. I'm still confused as to how the API works and how I can integrate it into my React Native front-end, or any front-end that's not Python-based for that matter.
I think you have to follow some online tutorial
And from my experiences, I think Flask is good choice for such case.
This is basic flask tutorial provided by tutorialspoint.com
You have to create a flask proxy, generate JSON endpoints then use fetch or axios to display this data in your react native app. You also have to be more specific next time.

How to combine Google App Engine with Cloud Natural Language

I thought what I was trying to do would be simple, but that seems to not be the case.
I've found that using the Natural Language API with Google Compute Engine is fairly straightforward, as I can simply import the needed libraries in Python.
This does not seem to be the case with App Engine, as I am plagued by import errors, as soon as I fix one, another arises.
Have any of you ever worked to combine these two services, and if so, how?
Thank you
App Engine Standard does not yet support Google Client Libraries (which I assume you are trying to import into your application), it is work in the development, so by now you can try with the following alternatives:
App Engine Flexible: it does support Client Libraries, you just have to vendor them into your application as if they were third-party libraries. You can follow this guide in order to add the google-api-python-client library appropriately.
REST API: you can use the REST API (which already has a stable version, v1). It might not be as convenient as Client Libraries, but you can make HTTP requests with your Python code and process their responses.
Compute Engine: as you pointed out in your question, you will be able to use Client Libraries from your custom Python runtime environment in any machine you want (either locally or an instance in Compute Engine).
UPDATE:
Actually, I have looked deeper into your issue and have been able to solve it using App Engine Standard by using the Google API Client Library (not Google Client Libraries), which is an alternative version that is available for the Standard environment. Below I leave a small working piece of code which you can populate with your own data and try in App Engine environment or even with the Local Development server.
from apiclient.discovery import build
service = build('language', 'v1', developerKey='<YOUR_API_KEY>')
collection = service.documents()
data = {}
data['document'] = {}
data['document']['language'] = 'en'
data['document']['content'] = 'I am really happy'
data['document']['type'] = 'PLAIN_TEXT'
request = collection.analyzeSentiment(body=data)
res = request.execute()
You will have to obtain an API key for authentication, as explained in the documentation, and you will also need to add the library as explained in the other link I shared.
Last, here you have the documentation on the available methods from the API. The example I provided is using analyzeSentiment(), but you can go with the one you need.
Hope it helps!

Google Cloud Endpoints discovery document changes / evolution support on iOS?

I'm implementing the iOS client-side of our Google Cloud Endpoints API, and want to know how Cloud Endpoints discovery documents get interpreted internally on iOS, so when I make changes on the Cloud Endpoints side (add a field, change a field name, delete a field) what happens to older clients?
I know that Cloud Endpoints exposes a REST JSON API for the Javascript/AngularJS side of things which we could tie into manually using something like AFNetworking on iOS. I'm familiar with how to manage API changes on the client in that scenario, but if it makes sense to utilize the Toolkit SDK / RPC implementation, then I'd rather do that.
Is this all handled by versioning the API, then? So older clients would request an older version of the API? Does the Google iOS SDK support semantic versioning then? I could see version numbers getting out of control quickly if not.
Note this is the python version of GCE.
You should be generating and using a client library, ultimately, if you don't want to both yourself with all kinds of implementation details of how to call the endpoints API. On the other hand, if you were to go with AFNetworking, it would be up to you do do your research as to how REST APIs can be called with AFNetworking. The REST API defined by endpoints can be read about in the documentation, and in addition you can use the API Explorer to test your methods and even capture the headers sent with these requests in your browser.
Secondly, it goes without saying that you shouldn't code an API, then change its specs radically without versioning it or notifying/updating any clients. The version system is implemented A) in the client library generated from your discovery doc and B) in the URL route of the REST API itself. You would want to choose whichever naming scheme for versioning that your target framework supports.
I hope this has cleared up any confusion for you.

Consume External XML API (with models, etc) with Flask

I'm going to be building a webapp that will consume an XML-based API, and I'd like to use Flask to make it.
Assuming I will be using SQLAlchemy for a database and something like FlaskWTF for forms, how can I get started using Flask in this way? I'm not really sure where to begin. I've heard the requests Python library a good way to go, but I don't know how to integrate that with db.model or other features of Flask, since I will be building an MVC-like app.
I've read through this but it doesn't really help me since I won't be using a local database. https://github.com/mitsuhiko/flask/wiki/Large-app-how-to
The requests library simplifies the work of making HTTP requests, but it does nothing in particular to help you consume the response XML. You might be more comfortable with Suds, PySimpleSOAP, or Flask-Enterprise to consume the SOAP data. Likewise, Flask alone does little to help you consume SOAP services specifically, but Flask complements other Python libraries made to work with SOAP.
Begin by writing and testing functions that interact with the SOAP data source. These functions should serve as the data models for your application, translating Python objects to/from SOAP requests. I presume you have no need for local caching or application-specific local data storage, since you mention that you won't be using a local database (though these can be added easily if desired).
Just as SQLAlchemy isolates the details of SQL from the rest of an app, your SOAP-backed data models should insulate the rest of your application from SOAP specifics. Build your app on these data models, relying on native Python objects as you'd find in most generic Flask examples.

Open-source examples of open-source GAE projects in Python?

There are plenty of well known sites that use GAE
Example of large sites running on Google App Engine
But I wonder if there are examples of python open-source projects built on the GAE that I can simply download and play with.
I find it easier to learn by doing rather than reading throught the docs. Having a working model that I can launch locally would be more useful than all the reference material in the world because it would show me how to structure, configure + some best practices.
If I could have my wish-list, I'd look for an example that:
Actually does something - not just static pages
Makes use of a number of different entities, preferably with some relationships between them
Some templates
Possibly a RESTFUL API
Using the builtin webapp framework (not django etc)
Thanks!
Take a look at Google App Engine samples repository.

Categories

Resources