Using PayPal classic SDKs in Django through JPype - python

I want to send automated payments using the PayPal APIs. As far as I know, currently there are only 2 ways to do it:
Using the Payouts Endpoints of the modern REST APIs
Using the Adaptative Payments from the "classic" APIs
The preferred option would be option 1, because there is already an official SDK available for Python, sadly this feature seems to be only available on the United States, the documentation states:
Merchants in the United States can register to use Payouts in the Live
environment as outlined in the following steps. Other merchants should
contact their Account Manager or customer service to enable Payouts.
So it seems there are some extra steps to enable Payouts, but they are very opaque about it and don't give so much information, it's unclear to me whether it's really available or not. (I have already contacted their tech support to get assistance, I'm waiting for their reply, I'm just asking this here as a backup plan).
If I want to use the Adaptative Payments on Python, more specifically on Django I have 3 options:
Implement a small Java wrapper around the official SDK and call it through Python using JPype
Implement a small Java wrapper and call it through the command line, or run it as a service and call it internally from the server.
Implement the required subset of the PayPal SDK in Python myself.
Option 3 is the most complicated, but probably the most efficient, however since it will not be officially supported, maintaining it can become problematic. Option 2 seems so easy to implement, but since the memory overhead of the JVM will be there anyway maybe it's better to interface it through JPype, which is the main point of this question.
Question details here:
Sorry for the large introduction, it ended up much larger than expected, now going to the point.
If I start the JVM in Django with JPype. Will this mean that each request (there will be a thread for each request, that's how web servers work) will start it's own JVM? Is it a good approach?

Related

NodeJS and Python combined architecture?

Could you give me an idea/concepts (not in code) on how could I link NodeJS and Python?
Let's say,
I have NodeJS up and running in PM2 (assuming I already know REST API) and I have a ton of data sets that I need to be ready to display to client side using socket.io (assumming I already know socket.io) as soon as possible.
I'm thinking to use Python. This is for me to implement the basics of machine learning.
In what concept should I start? I'd really love to hear your ideas.
Well you seem to be assuming way too many things, okay from your description I would suggest you to have a look at concept called microservice architecture.
This is how it will work let us assume you want to build an online shopping application where you have 2 main scenarios first is sell all items on your website and second you want to recommend products to your user(Your ML comes into play over here)
So as you said you already know REST API so what you would do is create a microservice (Consider it as a small nodejs application(Using either express or sails or any other framework) which has APIs exposed for all shopping related business logic) also you end up using fromtend technology viz. angularjs for your client side code. You'll show all this shopping stuff by calling your nodejs REST APIs from your angularjs client code. Node provides socket support via socket.io.
Similarly you write a small microservice in python(using Flask and Python-SocketIO) which takes your huge amount of data from datastore does all ML magic and returns recommended products for the particular user(which you received from your angularjs client application), and return it using Python-SocketIO to angularjs(or node application if you're maintaining your frontend logic there instead of angular).
You have provided very less detail so this is abstract view of what you can look into.
Since you're Python oriented for your ML code I'd suggest you to reduce the list of skills you need to learn and/or improve using Python for everything.
You could use Python-SocketIO and Flask, for example.

Delivering Python Processed data to the web

I have developed a python program that parses a webpage and creates a new text document with the parsed data. I want to deliver this new information to the web. I have no idea where to start with something like this. Are there any free options where I can have a site automatically call this python code upon request and update the new data to its page? Or is the only feasible solution here to have my own website/server that uses my code? I'm honestly pretty overwhelmed with many of the options when I try to begin doing a web-search for a solution like this. I have done a decent amount of application programming before so i'm confident in my ability to learn new things, but web protocols are all new to me so its hard to find a starting point.
Ultimately I want this python code to run automatically, or per request of a user, and deliver to the data to them. It could even be through an email, although that is probably less practical.
I personally have good experience using Google Appengine (and its free for a limited amount of requests). The downside is that it does not allow C-extensions or Python3.
If you want to host your own server, tornado is a good option I think. Tornado supports both Python2 and Python3.
There are a great deal of options available.. from 'traditional' virtual server or website hosts like a2hosting or godaddy to 'Cloud Application Hosts' such as Amazon EC2, Heroku or OpenShift.
For your case, and without knowing more, I would suggest that an application hosting is more appropriate, and that you should take a look at Heroku and Openshift in particular.
Define carefully what you want to achieve (how the users access your application, what they see, how they interact with it... etc..) and then evaluate these options based on those requirements.
Most offer a free trial, or even free services, depending on what you need! Good luck
If you've never worked with web technologies before this will be a overwhelming task, since there's a lot of different technologies involved, and many possible ways to combine them.
You'll probably want to start by familiarizing yourself with the very basics of the HTTP protocol.
Then you should read a bit on CGI server-side programming (the article also has a quick overview on HTTP).
Python can run both on CGI and WSGI (if the server provider allows such access), so you may also want to read about WSGI.
Once you grasp all these concepts, you should check this question for actual python techniques.
Also, since you seem to be under the impression you must pay to have a website/app deployed, you should know there are companies that host python apps for free

When to use Tornado, when to use Twisted / Cyclone / GEvent / other [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Which of these frameworks / libraries would be the best choise for building modern multiuser web application? I would love to have an asynchronous webserver which will allow me to scale easly.
What solution will give the best performance / scalability / most useful framework (in terms of easy of use and easy of developing)?
It would be great if it will provide good functionality (websockets, rpc, streaming, etc).
What are the pros and cons of each solution?
"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design". If you are building something that is similar to a e-commerce site, then you should probably go with Django. It will get your work done quick. You dont have to worry about too many technology choices. It provides everything thing you need from template engine to ORM. It will be slightly opinionated about the way you structure your app, which is good If you ask me. And it has the strongest community of all the other libraries, which means easy help is available.
"Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions". Beware - "microframework" may be misleading. This does not mean that Flask is a half-baked library. This mean the core of flask is very, very simple. Unlike Django, It will not make any Technology decisions for you. You are free to choose any template engine or ORM that pleases you. Even though it comes with Jinja template engine by default, you are always free to choose our own. As far as I know Flask comes in handy for writing APIs endpoints (RESTful services).
"Twisted is an event-driven networking engine written in python". This is a high-performance engine. The main reason for its speed is something called as deferred. Twisted is built on top of deferreds. For those of you who dont know about defereds, it is the mechanism through with asynchronous architecture is achieved. Twisted is very fast. But is not suitable for writing conventional webapps. If you want to do something low-level networking stuff, twisted is your friend.
"Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user". Tornado stands some where between Django and Flask. If you want to write something with Django or Flask, but if you need a better performance, you can opt for Tornado. it can handle C10k problem very well if it is architected right.
"Cyclone is a web server framework for Python that implements the Tornado API as a Twisted protocol". Now, what if you want something that is nearly as performant as Twisted but easy to write conventional webapps? Say hello to cyclone. I would prefer Cyclone over Tornado. It has an API that is very similar to Tornado. As a matter of fact, this is a fork of Tornado. But the problem is it has relativly small community. Alexandre Fiori is the only main commiter to the repo.
"Pyramid is a general, open source, Python web application development framework. Its primary goal is to make it easier for a Python developer to create web applications." I haven't really used Pyramid, but I went through the documentation. From what I understand, Pyramid is very similar to Flask and I think you can use Pyramid wherever Flask seems appropriate and vice-versa.
EDIT: Request to review any other frameworks are welcomed!
Source: http://dhilipsiva.com/2013/05/19/python-libraries-django-twisted-tornado-flask-cyclone-and-pyramid.html
This is obviously a somewhat biased answer, but that is not the same thing as a wrong answer; you should always use Twisted. I've answered similar questions before, but since your question is not quite the same, here are some reasons:
"Best Performance"
Twisted continuously monitors our performance at the speed.twistedmatrix.com website. We were also one of the first projects to be monitored by PyPy's similar site, thereby assuring the good performance of Twisted on the runtime that anyone concerned with high-performance applications in Python.
"Scalability"
To my knowledge, none of the listed frameworks have any built-in support for automatic scaling; they're all communication frameworks, so you have to do the work to communicate between your scaling nodes. However, Twisted has an advantage in its built-in support for local multi-processing. In fairness, there is a third-party add-on for Tornado that allows you to do the same thing. In recent releases, Twisted has added features that increase the number of ways you can share work between cores, and work is ongoing in that area. Twisted also has a couple of well-integrated, "native" RPC protocols which offer a construction-kit for whatever scaling idiom you want to pursue.
"Most Useful"
Lots of people seem to find Twisted very useful. So much so that many of them have extended it and made their extensions available to you.
"Functionality"
Out of the box, Twisted includes:
good support for test-driven development of all the following
TCP servers, clients, transport layer security
SSH client and server
IMAP4, ESMTP, POP3 clients and servers
DNS client and server
HTTP client and server
IRC, XMPP, OSCAR, MSN clients and servers
In this last department, at least, Twisted seems a clear winner for built-in functionality. And all this, in a package just over 2 megabytes!
I like #Glyph response.
Twisted is very comprehensive, rich python framework.
Twisted and Tornado have a very similar design.
And I like this design very much:
it's fast
easy to understand
easy to extend
doesn't require c-extensions
works on PyPy.
But I want to highlight Tornado, which I prefer and recently gain popularity.
Tornado, like Twisted, uses callback style programming, but it can be inlined using tornado.gen.engine (twisted.internet.inlineCallbacks in Twisted).
Codebase
The best comment is from http://cyclone.io site. cyclone tries to mix Twisted and Tornado because:
Twisted is one of the most mature libraries for non-blocking I/O available to the
public. Tornado is the open source version of FriendFeed’s web server,
one of the most popular and fast web servers for Python, with a very
decent API for building web applications.
The idea is to bridge Tornado's elegant and straightforward API to
Twisted's Event-Loop, enabling a vast number of supported protocols.
But in 2011 tornado.platform.twisted was out which brings similar functionality.
Performance
Tornado has much better performance. It also works seamlessly with PyPy, and get huge gain.
Scalability
The same like Twisted. Tornado has tornado.process and a lot of rpc services implemented on top of it.
Functionality
There are 71 Tornado based package, compared to 148 Twisted's and 48 Gevent's. But if you look carefully and compute median of packages upload time, you will see that Twisted ones are the oldest, then Gevent and Tornado the freshest.
Furthermore there is tornado.platform.twisted module which allows you to run code written for Twisted on Tornado.
Summary
With Tornado you can use a code from Twisted. There is no need to use cyclone which only twists your code (your code becomes more messy).
As for 2014, Tornado is considered as widely accepted and default async framework which works both on python2 and python3. Also the latest version 4.x brings a lot of functionality from https://docs.python.org/dev/library/asyncio.html.
I wrote an article, explaining why I consider that Tornado - the best Python web framework where I wrote much more about Tornado functionality.
(UPDATE: I'm sadly surprised about how few answers here recommend or even mention Gevent—I don't think it's in proportion to the popularity, performance and ease of use of this excellent library!)
Gevent and Twisted are not mutually exclusive, even though the contrary might seem obvious at first. There is a project called geventreactor which allows one to relatively smoothly leverage the best of both worlds, namely:
The efficient and cheap (cooperative green) thread model of Gevent, which is much easier to program in when it comes to concurrency—frankly, Twisted's inlineCallbacks is simply not up to the job in terms of performance when it comes to many coroutines, and neither in terms of ease/transparency of use: yield and Deferreds everywhere; often hard to build some abstractions; horrifyingly useless stack traces with both bare Deferreds as well as, and even more so with #inlineCallbacks.
All the built-in functionality of Twisted you can ever dream of, including but not limited to IReactorProcess.spawnProcess.
I'm personally currently using Gevent 1.0rc2 with Twisted 12.3 bridged by geventreactor. I have implemented my own as-of-yet unpublished additions and enhancements to geventreactor which I will publish soon, hopefully as part of geventreactor's original GitHub repository: https://github.com/jyio/geventreactor.
My current layout allows me to program in the nice programming model of Gevent, and leverage things such as a non-blocking socket, urllib2 and other modules. I can use regular Python code for doing regular things, as opposed to the learning curve and inconvenience of doing even simple, basic things the Twisted way. I can also easily use most 3rd party libraries that are normally either out of question with Twisted, or require the use of threads.
I can also completely avoid the awkward and often overly complex callback based programming by using greenlets (instead of Deferreds and callbacks, and/or #inlineCallbacks).
(This answer was written based on my personal experiences having used both Twisted and Gevent in real life projects, with significantly more experience using Twisted (but I don't claim to be a Twisted expert). The software I've had to write hasn't had to use too many of Twisted's features, so depending on the set of features you require of Twisted, the (relatively painless) extra complexity of mixing Gevent and Twisted might not be worth the trouble.)

What tracking solutions are available for server side code?

I'm working on a tracking proxy (for want of a better term) written in Python. It's a simple http (wsgi) application that will run on one (maybe more) server and accepts event data from a desktop client. This service would then forward the tracking data on to some actual tracking platform (DeskMetrics, MixPanel, Google Analytics) so that we don't have to deal with the slicing and dicing of data.
The reason for this implementation is that it's much easier and faster to make changes to a server process that we control rather than having to ensure every client in the wild gets updated if the tracking backend changes in some way.
I've been looking up info on the various options and I was hoping somebody here would have some good advice from their own experiences. Ideally we'd be able to use Google Analytics as it's free for any amount of usage but paid options are fine.
My only real requirement is either a good Python library or a well documented api that I can write a wrapper for (this seems somewhat lacking in GA when it comes to triggering events through any method other than their js or other provided libs).
N.B. We're not really tracking server code so something like NewRelic isn't appropriate, we're just decoupling a desktop application from the specifics of the tracking backend.
We ran into this same problem a bunch of times, we ended up building a suite of server-side analytics libraries to make this easier.
Segment.io has libraries for Python, Ruby, Java, Node, .NET and PHP that abstract the APIs for Mixpanel, KISSmetrics, Google Analytics and a bunch of other analytics services.
You could integrate the Python library once, and then send your data wherever you want. The data is proxied through Segment.io's hosted service. Hopefully this cleans up the mess of integrating a bunch of libraries, each with slightly different APIs. (The service is free for the first million events.)
Have you tried anything below?
The Google Data APIs Python Client Library has source specific to analytics
http://code.google.com/p/gdata-python-client/
http://code.google.com/p/gdata-python-client/source/browse/#hg%2Fsamples%2Fanalytics
https://developers.google.com/gdata/articles/python_client_lib
You might be able to borrow from these sources as well;
Google has something they are working on for mobile and source is available in PHP, JSP, ASP.net and Perl: https://developers.google.com/analytics/devguides/collection/other/mobileWebsites
I also came accross this in PHP http://code.google.com/p/php-ga/
As for others:
KissMetrics: http://support.kissmetrics.com/apis/python
MixPanel: https://mixpanel.com/docs/integration-libraries/python
DeskMetrics: don't seem to have python, http://docs.deskmetrics.com/index.html
Sorry I cannot provide information based off extensive experience with anything python related other then providing a few of these resources. I would be interested to see what you come up with.

TFS Webservice Documentation

We use a lot of of python to do much of our deployment and would be handy to connect to our TFS server to get information on iteration paths, tickets etc. I can see the webservice but unable to find any documentation. Just wondering if anyone knew of anything?
The web services are not documented by Microsoft as it is not an officially supported route to talk to TFS. The officially supported route is to use their .NET API.
In the case of your sort of application, the course of action I usually recommend is to create your own web service shim that lives on the TFS server (or another server) and uses their API to talk to the server but allows you to present the data in a nice way to your application.
Their object model simplifies the interactions a great deal (depending on what you want to do) and so it actually means less code over-all - but better tested and testable code and also you can work around things such as the NTLM auth used by the TFS web services.
Hope that helps,
Martin.
So, this question is friggin' old, but let me take a whack at it (since it keeps coming up in my google searches).
There's no officiall supported API for the on premise TFS (the MSFT hosted one has http://www.visualstudio.com/en-us/integrate/api/overview).
That said, you can always use Fiddler (http://www.telerik.com/fiddler) or something like it to inspect the calls that the web client for TFS is making to the server and do your magic to turn those into the scripts in python you want.
You'll need to run your python scripts under a service account that has TFS privs appropriate to what it is trying to do (read, update, confugure... whatever).
Since it sounds like you are just trying to read from TFS, this might be a really easy way for you to get what you want since an HTTP get to
http://yourserver/tfs/yourcollection/yourproject/_workitems#id=yourworkitemid
will hand you back (halfway) sane html payloads.
If you want lists of iterations or teams or whatever, then your service account needs to have the appropriate admin privileges and hit things like
http://yourserver/tfs/yourcollection/yourproject/_admin/_iterations
and use that response.

Categories