I want to create a desktop application written in python and using polymer as the front-end. To access the user interface, we use web browser such as chrome, mozilla, and safari. I did a lot of research in how to do this. The only reference I have is home Assistant, but I'm still don't quite understand about the architecture and the approach. Anyone have another solution or approach in how to do this?
python ships with a basic http server, however according to the docs it's not made for production use. But it's probably good enough for your use case (single user). On top of this you can implement a basic REST-Api and serve your frontend (.js/.html) as static content.
Or use a framework like django https://www.djangoproject.com/
Related
I have an idea for a web app and plan to learn Python as I go (right now I know html/css, some javascript, some php and sql). The app would be able to manipulate and analyze audio files, among other things.
Ideally, I'd like to make the app available through my wordpress site so that I can take advantage of WordPress's login management and the plugin s2member's subscription management and content restriction capabilities.
Is that possible? Would it even make sense?
If not, is there a better alternative to automate all of that (the subscription management, logins, payment processing, content restriction, etc) without having to code it myself?
I suggest you develop a REST API in Python and extend your Wordpress site to consume that API.
For the Python side, you could go with Flask and use Flask-RESTful.
For the Wordpress side, have a look at this question.
Sure, if you meet a couple of conditions:
The server your wordpress site is on also has python
And you have the ability run arbitrary python scripts on said server.
Here's a (very contrived) example of how to do it from a plugin:
call-python.php (plugin file):
<php
/*
Plugin name: Call Python
Author:..
....
*/
$pyScript = "/path/to/app.py";
exec("/usr/bin/python $pyScript", $output);
var_dump($output);
And the python script app.py:
print("Hello, World")
And that's it! That will dump Hello, world to the body. Obviously you'll need a bit more for a more complicated python app, but it will work.
Like others are saying, there may be better "more correct" ways of doing it. But if your end goal is to run a python app from WordPress it's possible.
I'm trying to build a niche social network like Instagram as a Python/Django application.
So the things I need, regarding architecture, are (I guess):
REST API (e.g. api.mystagram.com).
Public website (www.mystagram.com or mystagram.com).
URL shortener (e.g. mystagr.am).
Android app
iPhone app
Windows Phone app
...
Before this I only built simple to some less-simple websites, but never extremely complex with own custom APIs or so. I have never build my own REST API before (I have used other REST APIs though) or even built an Android/iPhone app and distributed it in the Play Store/App Store (I have made some typical hello world examples though).
So, the most important thing to me seems to create a kick-ass REST API first and proceed from there. I am blocked however by a few questions.
How should I organize the projects for the public website and REST API? Should these be separate Django projects or should I create only one Django project and add both the public website and REST API as an internal Django module?
Should the public website also make use of the REST API? Or is it better to just use the plain Django models for this?
Thanks in advance for any help! If somebody knows some great presentations or so on this topic (architecture), always welcome!
Kind regards,
Kristof
Django REST Framework
https://github.com/tomchristie/django-rest-framework
Very well maintained, great documentation, easy to use.
I think Tastypie will do what you want. And its simple and easy. Check this out - http://django-tastypie.readthedocs.org/en/latest/!
To Answer your first question, It would be good practice to put public web site and REST APIs into one django project. Now days every web application contains public web site as well as rest apis for mobile app. So it would be easier to maintain both website and rest apis if they both in one application. Below is Django REST Framework link.
https://github.com/tomchristie/django-rest-framework
For second question, Yes you can use rest apis in website also. But in general you don't need to do it. In most of the cases django model works for you.
I need to create web application, which can be reached by user as regular web site and as XML-RPC web service. Also web site should have mobile version. I'm planning to use next technologies:
Django (for web frontends (regular and mobile)).
Pyramid (for web service).
SQLAlchemy, Memcached (for persistence level)
Later other projects can reach this data and providing logic, so I think it is better to make two tiers. I see it in next way:
Tier 1. Main logic service level. This level will provide API for frontend applications (Django powered web site, for example).
Tier 2. Different mostly end client applications (web site, API for remote client devices).
For communication between this tiers I'm planning to use XML-RPC protocol.
In this case it will be easy to scale it and add new front end application or connect another projects to this (I believe it).
I have main question, -- what can I use to make it easy build first tier? Maybe there is some framework good for that?
And what do you think about this whole architecture. Because I'm filling that I'm thinking in Java terms developing in Python. Maybe there is some another idioms in Python world for such situations.
Thanks for you time and help.
P. S.
Some links for reading are welcome.
This architecture really makes no sense. You're using Django, a full-stack web framework, for the front end, but not using it for the database. And you're using Pyramid, another full-stack web framework, for the web service side, thus ensuring that you duplicate all the business logic.
Much as I am an advocate of Django, I would say it has no place in your architecture. It looks like the only thing you're really using it for is URL routing and templates, both of which Pyramid does itself fine - you can even use Jinja2, which is based on Django's template language, as the template language in Pyramid if you like.
Doing it this way means that you can share the business logic between the front-end and web service code, since you'll almost certainly find that a lot of it will be the same.
I must say also that I don't understand the division into tiers, which you have described as separate from the front-end/web service division. To me, the web service is the second tier. It makes no sense to have a further division.
You should checkout the Turbogears framework as it is composed of several popular components: ORM with sqlalchemy, pylons for logic and support for WSGI, permits support for several templating engines for the frontend... endless.
I use it for several web-services behind AJAX-enabled front-ends (like Flex-based apps, among others). You can front end the TG2-based webapp with apache or your favorite WSGI-enabled web server too.
Checkout their website since they have a tutorial to setup a wiki in 20 minutes.
Cheers!
I am currently working on a project to create simple file uploader site that will update the user of the progress of an upload.
I've been attempting this in pure python (with CGI) on the server side but to get the progress of the file I obviously need send requests to the server continually. I was looking to use AJAX to do this but I was wondering how hard it would be to, instead of changing to some other framerwork (web.py for instance), just write my own web server for receiving the XML HTTP Requests?
My main problem is that sending the request is done from HTML and Javascript so it all seems like magic trickery at the moment.
Can anyone advise me as to the best way to go about receiving these requests on the server?
EDIT: It seems that a framework would be the way to go. Would web.py be a good route to take?
I would recommend to use a microframework like Sinatra for Ruby. There seem to be some equivalents for Python. What python equivalent of Sinatra would you recommend?
Such a framework allows you to simply map a single method to a route.
Writing a very basic HTTP server won't be very hard (see http://docs.python.org/library/simplehttpserver.html for an example), but you will be missing many features that are provided by real servers and web frameworks.
For your project, I suggest you pick one of the many Python web frameworks and run your application behind Apache/mod_wsgi.
There's absolutely no need to write your own web server. Plenty of options exist, including lightweight ones like nginx.
You should use one of those, and either your own custom WSGI code to receive the request, or (better) one of the microframeworks like Flask or Bottle.
I want to develop a tool for my project using python. The requirements are:
Embed a web server to let the user get some static files, but the traffic is not very high.
User can configure the tool using http, I don't want a GUI page, I just need a RPC interface, like XML-RPC? or others?
Besides the web server, the tool need some background job to do, so these jobs need to be done with the web server.
So, Which python web server is best choice? I am looking at CherryPy, If you have other recommendation, please write it here.
what about the internal python webserver ?
just type "python web server" in google, and host the 1st result...
Well, I used web frameworks like TurboGears, my current projects are based on Pylons. The last ist fairly easy to learn and both come with CherryPy.
To do some background job you could implement that in pylons too.
Just go to your config/environment.py and see that example:
(I implemented a queue here)
from faxserver.lib.myQueue import start_queue
...
def load_environment(global_conf, app_conf):
...
start_queue()
It depends on your need if you simply use CherryPy or start to use something more complete like Pylons.
Use the WSGI Reference Implementation wsgiref already provided with Python
Use REST protocols with JSON (not XML-RPC). It's simpler and faster than XML.
Background jobs are started with subprocess.
Why dont you use open source build tools (continuous integration tools) like Cruise. Most of them come with a web server/xml interface and sometimes with fancy reports as well.
This sounds like a fun project. So, why don't write your own HTTP server? Its not so complicated after all, HTTP is a well-known and easy to implement protocol and you'll gain a lot of new knowledge!
Check documentation or manual pages (whatever you prefer) of socket(), bind(), listen(), accept() and so on.