Is it possible to use GCM with a python GAE backend? - python

I have a python GAE service, and I want to push notifications from the server to devices. The tutorial available for GCM is written for Java, and runs on ant+Tomcat/Jetty+JAE. I was under the impression that GCM would be a language-agnostic web service, and that I would be able to send push notifications regarding of my server-side platform.
Was I mistaken about GCM being compatible with my python GAE
backend?
If I CAN use it with my existing server, what instructions
can I follow (or adapt) to get started with sending notifications to
a mobile client?

Sure you can. GCM has a JSON REST API that you can work against. First you need to register you project here: http://developer.android.com/google/gcm/gs.html.
You basically do this:
Acquire you API key from http://developer.android.com/google/gcm/gs.html#access-key
Construct your payload, a dict containing registration_ids, data etc
Using url.fetch https://developers.google.com/appengine/docs/python/urlfetch/ to send the data as a JSON string to the GCM API
Here's another question with some code. Google Cloud Messaging HTTP Error 400: Bad Request and a blogpost (in not english, i think spanish. but there some sample code) http://pforray.wordpress.com/2012/07/05/ejemplo-gcm-en-appengine-python/

Use gcm-client
pip install gcm-client
Reference:
https://pypi.python.org/pypi/gcm-client/

Here you can find a module for Python interface for sending push notifications via Pushwoosh.
https://github.com/dbtsai/python-pushwoosh
You can use it for sending messages via Pushwoosh (it's free) or adapt it for your needs.

Related

How to integrate Django API with XMPP server (ejabberd)

I'm currently working on a project where I'm using Django rest framework (DRF) for the backend.
I need to implement one to one chat on this application. For this, I'm using XMPP server. I'm using ejabberd as XMPP server.
Now, I need to create users in the ejabberd server using my API built with DRF.
I need to achieve following things with my API:
create new users in the ejabberd server
create rooms in the ejabberd server
fetch all the available rooms.
The username will be fetched or retrived from the frontend.
Is there any Python API client or Django API client to do this in the ejabberd server? Like how there is simple-xmpp for node js
I have seen many python packages for this. some of them are,
pyjabberd
xmppy
django-xmpp
I'm not sure which one to use and I don't know whether is it possible to implement the above using any of these packages.
All those libraries that you mention seem to be to write XMPP clients. In that case, you can write a small XMPP client that will attempt to register account in a xmpp server (being ejabberd or whatever), that joins a MUC room, configures it to be persistent, then requests the lists of rooms...
A completely different approach would be to call API commands that ejabberd provides. As you can see in the API documentation, there are commands to perform precisely what you want, and many more: register,
create_room_with_opts,
muc_online_rooms.
And how to call this API? For playing and checking what those commands do, you can use the ejabberdctl command-line script. Probably you will later want to use ReST (then configure mod_http_api) or XML-RPC (in that case configure ejabberd_xmlrpc). See
Understanding ejabberd commands, and also check the example configuration and example calls using curl.

how can i send some data from php to python

I have a running python application that needs to receive some data and process them. and I also have a PHP server that can get these data. I want to send JSON data from PHP to my python app.
anyway except running a python web server and send data to it, or insert into DB and get from DB with python?
thanks.
I tried using python cherryPy web server.
#Niklas D It would be easier to answer your question, if you can give some more context about the application or use case you want to solve.
Some further possibilities are:
Glue Code (I never did it with python and php only C++ with python, but you should be able to find examples on the internet e.g. https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages#PHP )
Messaging Systems like RabbitMQ, ActiveMQ, ZeroMQ, etc.
Redis (I know you said except writing to a database, but Redis provides some features for publish subscribe https://redis.io/commands/pubsub which allows you to write to Redis from the one side and get data on the other side without polling the db all the time, which is the issue you have with using a database I guess) It's a bit easier to setup and use, than a messaging system.
TCP connection between the python and php application. https://medium.com/swlh/lets-write-a-chat-app-in-python-f6783a9ac170
If you want to send data to a python application using web protocols, i.e send POST, GET requests etc then you need to create a python web app to receive and handle those requests. Which in turn needs to be running off a webserver or you could build serverless functions to handle this, see https://serverless.com/
If you want to get data using a python application, i.e the python app sends POST and GET requests etc to your php app to ask for the JSON payload you can build an app using python's standard requests library https://docs.python.org/3/library/urllib.request.html or better still us the Requests package http://docs.python-requests.org/en/master/
Or you could do something and save the JSON file to disk and then open it with your python app. You'd need to set up scheduling or make your php app execute python code on the server... This last suggestion is a bad idea please don't unless your app is isolated and not publicly accessible or you know how to lock down your security.

PeekBatch in python azure

Is there a python API for reading all message present in a queue at that time? I found the api for .net:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.queueclient.peekbatch?view=azure-dotnet#Microsoft_ServiceBus_Messaging_QueueClient_PeekBatch_System_Int32_
As I known, Azure SDK for Python is wrapped Azure REST API, there is only a REST API to peek a message at one time, so the answer is no.
And there are some issues for this needs on Azure GitHub repo as below, the offical team recommended using AMQP instead of HTTP to peek messages.
Add support ReceiveBatch in servicebus.py
ServiceBus Batch Receive support
Hope it helps.

Client-Server framework for python

I'm currently working on a University project that needs to be implemented with a Client - Server model.
I had experiences in the past where I was managing the communication at socket level and that really sucked.
I was wondering if someone could suggest an easy to use python framework that I can use for that purpose.
I don't know what kind of details you may need to answer so I'm just going to describe the project briefly.
Communication should happen over HTTP, possibly HTTPS.
The server does not need to send data back or invoke methods on the clients, it just collects data
Many clients send data concurrently to server, who needs to distinguish the sender, process the data accordingly and put the result in a database.
You can use something like Flask or Django. Both frameworks are fairly easy to implement, Flask is much easier than Django IMO, although Django has a built in authentication layer that you can use, albeit more difficult to implement in a client/server scenario like you need.
I would personally use Flask and JWT (JSON Web Tokens), which will allow you to give a token to each client for authentication with the server, which will also let you differentiate between clients, and you can use HTTPS for your SSL/TLS requirement. It is tons easier to implement this, and although I like django better for what it brings to the table, it is probably overkill to have you learn it for a single assignment.
For Flask with SSL, here is a quick rundown of that.
For JWT with Flask, here is that.
You can use any database system you would like.
If I understood you correctly you can use any web framework in python. For instance, you can use Flask (I use it and I like it). Django is also a popular choice among the python web frameworks. However, you shouldn't be limited to only these two. There are plenty of them out there. Just google for them.
The implementation of the client depends on what kind of communication there will be between the clients and the server - I don't have enough details here. I only know it's unidirectional.
The client can be a browser accessing you web application written in Flask where users send only POST requests to the server. However, even here the communication will bidirectional (the clients need to open the page which means the server sends requests back to the client) and it violates your initial requirement.
Then it can be a specific client written in python sending some particular requests to your server over http/https. For instance, your client can use a requests package to send HTTP requests.

Parse REST api client receiving push notifications

I was wondering if it is possible to have a REST api based Parse client that can receive Push notifications.
In particular, I'm using Python for my "device" code on Raspberry Pi, and I'm using the ParsePy library which is a wrapper on top of the Parse REST api.
It doesn't look like Parse supports receiving Push notifications via the REST api (it explicitly says it doesn't support receiving Push notifications in Javascript, while the REST api section doesn't even talk about receiving push notifications).
If I've overlooked something at receiving push notifications can be achieved in a Python client, any pointers would be totally appreciated.
If it is not supported, is there any plan in the works for a Python client SDK (that would support it)?
Thanks,
Sridhar

Categories