6 ms·
Show HN: Pump, a dead simple Pythonic abstraction of HTTP.
- radarsat1 15y agoLooks useful, though I think any modern abstraction like this should come with at least the scaffolding for future support of websockets. (They are a bit in flux right now, but will ultimately be incredibly useful.)
- MostAwesomeDude 15y agoWebSockets is not HTTP and should not be handled like HTTP. I just reimplemented a WS wrapper by removing its dependency on HTTP stuff, and ended up decreasing its LOCs and complexity.
- pbreit 15y agoThis seems interesting but I'm not sure why. What are some use cases?
- teej 15y agoI believe the intent is to be Rack[1] for Python. The beauty of Rack is that I can build a new web framework, web server, or web app plugin and have it "just work" with the rest of the ecosystem. And because the Rack API is so simple, building to spec is easy. In the Ruby world if I want to use the awesome library Sass all I have to do is: gem install sass Because it functions as a Rack plugin it automatically works with any Ruby web framework & Ruby web server combo I choose. No special setup required. ----- [1] http://rack.rubyforge.org/ http://rack.rubyforge.org/
- pyninja 15y agoYes, Pump was heavily inspired by Rack and especially Clojure's Ring (https://github.com/mmcgrana/ring https://github.com/mmcgrana/ring).
- irahul 15y agoI don't get the purpose. WSGI was meant to low level to cover the common minimum. If you want request, response semantics, use a higher level library - I use werkzeug which wraps wsgi, or flask which is small web framework built on werkzeug. I don't think anyone other than wsgi library implementors code to WSGI. WSGI would be a problem if that's how python web programming was to be done - but that's not the case.
- BarkMore 15y agoI like how the circle if inspiration loops back to Python: Python WSGI inspired Ruby Rack. Ruby Rack inspired Clojure Ring. Clojure Ring inspired Python Pump.
- irahul 15y ago# WSGI def app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) yield 'Hello World\n' # Rack app = proc do |env| [ 200, {'Content-Type' => 'text/plain'}, "a" ] end WSGI is the Rack for Python. In fact, WSGI predates Rack, and Rack is WSGI inspired.
- pyninja 15y ago# Pump def app(request): return { "status": 200, "headers": {"content_type": "text/plain"}, "body": "Hello World"}
- irahul 15y agoYou sure have put effort and the project looks good, but I am missing the purpose. If the problem it tries to solve is parsing environ to form response objects, or providing vanilla middlewares, that problem is very well solved by a wsgi library. Have you looked at werkzeug?
- pyninja 15y agoPump aims to replace WSGI entirely. That is, I believe it does a better job of what WSGI was intended to do. I understand your point that web developers don't necessarily work with WSGI on a day-to-day basis. But if you look at the Ruby web community, Rack middlewares are much more prevalent than WSGI middlewares. Application developers (as opposed to framework developers) often add functionality as a Rack middleware, so that it can be reused in different applications, even using different frameworks. Why isn't that happening with Python as much? In the Python world, instead of writing even simple middlewares to for basic functionality like https://github.com/adeel/pump/blob/master/pump/middleware/params.py https://github.com/adeel/pump/blob/master/pump/middleware/pa... or https://github.com/adeel/pump/blob/master/pump/middleware/cookies.py https://github.com/adeel/pump/blob/master/pump/middleware/co..., every framework ends up reimplementing it. I believe this is because the WSGI API is ugly and not as easy to understand as it could be (just look at the average WSGI middleware).
- pyninja 15y agoBuilding web apps! Basically, it's meant to be a replacement for WSGI. In my view, the problems with WSGI are that it has an unpythonic API (see: start_response and environ), and that it doesn't come with standard middleware that all frameworks use, so they all end up reinventing the wheel. Pump does a better job of abstracting out the details of HTTP, and also comes with a lot of useful middleware. This makes it really simple to write a web framework: just implement the routing and glue together a bunch of middlewares. For an example, see Picasso (https://github.com/adeel/picasso https://github.com/adeel/picasso), a simple but functional framework I built on top of Pump.
- irahul 15y ago> In my view, the problems with WSGI are that it has an unpythonic API (see: start_response and environ), Why do you find `start_response` unpythonic?
- pyninja 15y agoThe problems with start_response have been discussed at length in Web-SIG. As far as I know, they're planning to remove it from the spec in WSGI 2.0 (whenever that's published).
- irahul 15y agoI see http://wsgi.org/wsgi/WSGI_2.0 http://wsgi.org/wsgi/WSGI_2.0 mentions: > We could remove start_response and the writer that it implies. I searched for `wsgi start_response issues` and didn't get anything useful. Care to point out what's the fuss with start_response and why it's unpythonic?
- pyninja 15y agoHere is an example of a thread where it's discussed: http://mail.python.org/pipermail/web-sig/2009-November/thread.html#4224 http://mail.python.org/pipermail/web-sig/2009-November/threa...
- 15y ago
- benatkin 15y agoHere's another NoWSGI HTTP server library (Brubeck): http://news.ycombinator.com/item?id=2770866 http://news.ycombinator.com/item?id=2770866
- pyninja 15y agoI hadn't seen this, looks interesting.
- xioaqmajtt 15y agowelcometo: http://www.fullmalls.com http://www.fullmalls.com The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time. free shippingcompetitive priceany size availableaccept the paypal ===== http://www.fullmalls.com http://www.fullmalls.com ===== jordan shoes $32nike shox $32Christan Audigier bikini $23 Ed Hardy Bikini $23Smful short_t-shirt_woman $15ed hardy short_tank_woman $16Sandal $32christian loubo utin $80 Sunglass $15 COACH_Necklace $27handbag $33AF tank woman $17puma slipper woman $30 ===== http://www.fullmalls.com http://www.fullmalls.com ===== ===== http://www.fullmalls.com http://www.fullmalls.com ===== ===== http://www.fullmalls.com http://www.fullmalls.com ===== ===== http://www.fullmalls.com http://www.fullmalls.com ===== ===== http://www.fullmalls.com http://www.fullmalls.com =====
- teyc 15y agoAs far as web frameworks go, wsgi is pretty low level already. If you want to do a framework, move to a narrow vertical, it might get more traction.
- collint 15y agoThe Rack style API is nice for the simplicity. I <3 it. The Rack style api is NOT a great representation of the HTTP protocol. Specifically anything with a streaming or chunked response. start_response/yield may not be the absolute best API for this, I haven't thought to much about that. But if you go look into what was done in Rails 3.1 for chunked responses you may realize it's not actually too great.
- jrockway 15y agoThe point of WSGI is not to be a good abstraction of HTTP. As an app author, you aren't supposed to care. The advantage of WSGI is that it's standard, and everything uses it. That means you can use any web framework with any web server, and it will all Just Work. When you write your own copy of WSGI to change how some words are spelled, you don't gain much, but you lose the whole WSGI community. This seems rather pointless to me.
- irahul 15y ago> That means you can use any web framework with any web server, Or if you are really keen on working low level, you use a nice wsgi library viz. werkzeug.
- dschobel 15y agoFTA: Take advantage of existing WSGI tools. Pump comes with adapters for serving Pump apps with WSGI servers and converting WSGI middleware to Pump middleware.
- clarkevans 15y agoIt seems like the author here is comparing Pump to WSGI -- perhaps a better comparison is to Ian Bicking's WebOb (http://webob.org http://webob.org) or Armin Ronacher's Werkzeug (http://werkzeug.pocoo.org/ http://werkzeug.pocoo.org/). WSGI is a low-level protocol that provides a minimal interface to an HTTP Server ala CGI. It is purposefully not an application-level HTTP toolkit. For example, a WSGI component takes an input stream and returns an iterable which could yield output chunks... of perhaps in infinite data stream. These edge cases are sometimes very important and why the interface is designed as it is: inconvenient as it may be for simple apps.
- saurik 15y agoI don't see any way to use Pump to stream data in (a very long POST) or stream data out (a very long body). While it is certainly "dead simple", claiming that it is "what WSGI should have been" is a serious stretch.
- LeafStorm 15y agoOne issue that I have with it is that there is no distinction between script name and path info. Obviously, you don't have to call them that, but not having a distinction between the two makes it impossible to serve two Pump apps on the same domain and dispatch between them. Also, there's no clearly defined format for middleware added by keys - the included middleware just adds plain old keys as it pleases. But more generally, I don't really see the purpose of this. WSGI is obviously not ideal (thanks to start_response and CGI environment variables), but it's also quite firmly in place in the Python world. Not to mention that it would take the Pump library quite a while to catch up to Werkzeug or WebOb in terms of having all the necessary HTTP primitives implemented. (Multipart parsing, anyone?) Unless the server makers get on board, Pump is pretty much just an added layer of complexity on top of WSGI. Instead of "server | WSGI | WSGI library | framework", you have "server | WSGI | Pump adapter | Pump library | frameworK".
- justin_vanw 15y ago"What WSGI should have been." Well, not at all. Pump is what werkzeug, webob, and other more friendly wrappers on WSGI already are. Basically pointless duplication of work, without understanding why WSGI can't be this simple. One basic reason that WSGI can't be as simple as just returning a dictionary is that you don't necessarily want the entire body of your response pre-computed before starting to return data to the client. What about long running connections? What if you want to return the head of the response immediately, so the client can start pulling css and js while you compute the body of the response? What if you want to do chunked encoding to support long polling connections, or responses where you don't know the response size beforehand? Pump is basically doing what lots of other things already do, except without quite understanding HTTP quite as well.
- pyninja 15y agoThanks for the feedback. I'm not willing to accept that WSGI couldn't be this simple. Pump's specification is modeled on Ring for Clojure (https://github.com/mmcgrana/ring https://github.com/mmcgrana/ring), and I'm sure there's a way Ring gets around the issues you mention. I'd never had to do any of those things before but I'll look into it now.
- justin_vanw 15y agoWerkzeug and WebOb already do what you are trying to do, and they do it in a completely fantastic way. I'm not saying that to discourage you from learning and contributing, but what do those two libraries do wrong that you are hoping to improve on? In the meantime, don't bash WSGI until you understand why it is the way it is.
- pyninja 15y agoWerkzeug and WebOb are not what I'm trying to do. I'm reposting a reply I made earlier to irahul: Pump aims to replace WSGI entirely. That is, I believe it does a better job of what WSGI was intended to do. I understand your point that web developers don't necessarily work with WSGI on a day-to-day basis. But if you look at the Ruby web community, Rack middlewares are much more prevalent than WSGI middlewares. Application developers (as opposed to framework developers) often add functionality as a Rack middleware, so that it can be reused in different applications, even using different frameworks. Why isn't that happening with Python as much? In the Python world, instead of writing even simple middlewares to for basic functionality like https://github.com/adeel/pump/blob/master/pump/middleware/params.py https://github.com/adeel/pump/blob/master/pump/middleware/pa... or https://github.com/adeel/pump/blob/master/pump/middleware/cookies.py https://github.com/adeel/pump/blob/master/pump/middleware/co..., every framework ends up reimplementing it. I believe this is because the WSGI API is ugly and not as easy to understand as it could be (just look at the average WSGI middleware).
- mkramlich 15y agoRolling your own small web framework in some arbitrary language seems to be one of the easier ways to add "open source project author" to one's resume. Not that I'm knocking it. But after you've seen the wheel reinvented the Nth time, you get increasingly less impressed on N+1, N+2, etc.
- est 15y agoI never understand the mentality of modern wsgi/cgi design. Passing parameters using environ? Why not directly as a python request object?
- LeafStorm 15y agoFor consistency. If there was a request object, there would need to be some sort of standard implementation that there was always access to so that the object could be properly instantiated, instance tested, etc. By using a plain old dict, you ensure compatibility at the cost of attribute access. Also because WSGI is designed to be low-level, and if you want a request object you should really be using a library or framework.
- est 15y agoBut the old model sucks. If a process can handle more than one request, how does it change environ if there is only one process?
- nikcub 15y agoby passing dicts you are removing what makes WSGI work so well: lazy loading, chunked responses, middleware (encoding, caching etc.) by decorating, iterators/generators etc. your solution is going to be slower, more memory intensive and will not be able to be http 1.1 compatible. there is a reason why WSGI was designed the way it is
- moreyes 15y agoIt is ironic that they mention "don't have to reinvent the wheel" in that page.
- dlamotte 15y agohttp://xkcd.com/927/ http://xkcd.com/927/ Seems relevant here...