Archive for the ‘Python’ tag
Using Mixpanel API In Google App Engine Applications (Python)

We started using MixPanel to get realtime statistics on user engagement in our application. We’ve been using MixPanel before for funnel tracking, but you can’t really appreciate their service until you start using their event tracking. It is truly realtime (as advertised) – the second the user performs an action on your application, you see it on your dashboard.
Besides the realtime reporting what I really like about MixPanel is the fact that they allow easily reporting from your backend and not only from frontend/Javascript (as opposed to Google Analytics).
Within their documentation they have code samples in many languages, including Python. But their Python sample requires ability to start new processes on the server you’re running – something not possible on App Engine. Therefore I changed it to use URLFetch in RPC mode (so that calls to Mixpanel won’t block the call):
It could be re-factored more, like allowing setting the project token outside the function call, but that I will leave for you to do
(and if you do, please share with us)
Arik
App Engine: Mapping Entities Using Deferred Tasks
I recently started using deferred tasks in my App Engine application. I’m using them mainly for two things:
- splitting user requests into two pieces – one that being done immediately and one that being done in the background, to speed up the response time.
- mapping (iterating over) all my entities to calculate various statistics.
I won’t provide here details on how to use deferred tasks, because this is described in detail in a great article by Nick Johnson, which I highly recommend reading. One thing I do want to share from my experience, is my implementation of the Mapper base class:
This implementation is taken from Nick’s article mentioned above, but I made some changes to it. The first change is giving subclasses the ability to set the property to order the entities by. I needed this, because I found out that when your entities have custom key names ordering by key breaks for some reason.
The other change is re-factoring the way the next batch starts. It seems to me that in the sample provided in the article there’s an error in the indentation, resulting in the code not doing batching properly and can even break in some situations. In my version every task run maps only one batch (or less). This is sub optimal in terms of # of tasks it takes to map all your entities, but as long as you don’t have really a lot of entities this is not such an issue.
I really would love to hear others’ comments no my changes and about how you use deferred tasks or map your entities.
Arik
How To Send SMS Message From Python Via Skype
In case you didn’t know, Skype offers an extensive API for their application. This API can be used via Java library, COM module or a Python library. The Java library, COM Module and Python library all share similar features and I decided to try out the Python library. What I wanted to do is to write a simple Python script that uses the Skype API to send SMS message from Skype. After going through their API documention, I was ready to go and the outcome was this short script:
I think that the code is pretty straightforward and doesn’t require additional explaining. Feel free to ask questions at the comments.
Arik
Google Apps Engine isn’t Amazon Web Services
For those of you who don’t know who Guido is, he’s the creator of Python and now works for Google. Recently he moved to the Google Apps Engine team. If you want a quick introduction to Google Apps Engine, just read this blog post and then watch the following two videos: (the first one shows creation of a sample application and the other one is Guido’s recap of Google Apps Engine):
Currently the Google Apps Engine is in a preview beta, and to the moment of writing this post, there’re no more inventions left. If you still want to experience the Google Apps Engine, you can download the SDK. Currently they support only Python, but they plan to support more languages as the product will mature. It really makes me curious to see what will be next language that they will support.
One important thing to understand is that Apps Engine isn’t Amazon Web Services. They both offer virtualization services, but in a different style:
Will it replace Amazon? It sure doesn’t look like it from where I sit. In fact, I don’t see this as much of a competitor to Amazon Web Services. There’s some overlap in some small area (hosted web apps on EC2), but I doubt that’s the bulk of Amazon’s business. As I said, we’ll likely end up using both (and other providers as they come along, too).
In my opinion, in current stage, Google Apps Engine is aimed at and more suitable for the most standard web applications. What’s not a standard web application? YouTube for instance – because it requires not only serving loads of pages (data), but also some computation (like converting video formats).
One things is sure – now that there’s competition to AWS, it will make things much more interesting.
Arik