CRUD in Pyramid, using Cornice and SQLAlchemy
Hey Gael's idea on using a class to define all methods for a service, gave me another idea: add a light CRUD on the top of SQLAlchemy, in Cornice I post it here and now because I think it overlaps a little bit Gael's proposal The idea would be to point to Cornice an SQLAlchemy mapping and have it published as a set of RESTful APIs. Example (see the __path__ attribute): from sqlalchemy.ext.declarative import declarative_base, Column from sqlalchemy import Integer, String, Text from cornicedb import DataPublisher _Base = declarative_base() class Application(_Base, DataPublisher): __tablename__ = 'applications' __path__ = '/applications' id = Column(Integer, primary_key=True) user = Column(String(256), nullable=False) collection = Column(String(256), nullable=False) origin = Column(String(256), nullable=False) last_modified = Column(Integer, nullable=False) data = Column(Text) This would generate automatically these REST-ish URIs: - GET /applications - get the whole table, with batch options - POST /applications - adds one or several rows - DELETE /applications - adds one or several rows - GET /applications/1 - get the row of id 1 - PUT /applications/1 - updates the row of id 1 - DELETE /applications/1 - delete the row of id 1 - etc.. Other features I have in mind: - you can override or deactivate any one of these API by adding get() post() etc, methods to the class - you can write pre/post hooks, to add authentication etc - you can define what we already have in cornice (validators, etc) One pitfall: have the view and the data controller mixed in one single class. If we start to have more code atop the data, it could become a mess Cheers Tarek -- Tarek Ziadé | http://ziade.org -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Cornice 0.6 released
On Thu, Dec 22, 2011 at 4:04 PM, Robert Forkel xrotw...@googlemail.comwrote: One more thing which bothered me when looking at the Service implementation: Why the 'acl' parameter and not a full context factory? I'm playing with cornice to add an API to an existing webapp, so I already have these context factories around but cannot pass them into a cornice service. I don't see any good reason -- so I'd be tempted to fix this. I am cc'ing Ryan that did that first implementation Cheers Tarek regards robert On Dec 21, 11:00 pm, Gael Pasgrimaud g...@gawel.org wrote: Hi, On Wed, Dec 21, 2011 at 11:24 AM, Tarek Ziadé ziade.ta...@gmail.com wrote: We'd love feedback new contributors ! Looks like a clever way to build some APIs. I have a project where I may switch to cornice. But I have a few questions. First, are you planning to add a support for class based views ? I'd like to define my services like this: @cornice.service(path='/users') class User(object): def __init__(self, request): self.request = request def get(self): do get Where get / post / put / delete and index (to get a listing) routes will be automatically added if they are implemented. This is something that missing from Pylons the framework (at least for me). Does cornice support sub resources ? (eg: with a path like /users/{id}/pages/) And the last one. Can we use the pyramid authentication/authorisation stuff with cornice ? Cheers Tarek -- Tarek Ziadé |http://ziade.org -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group athttp:// groups.google.com/group/pylons-discuss?hl=en. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en. -- Tarek Ziadé | http://ziade.org -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: CRUD in Pyramid, using Cornice and SQLAlchemy
On Thu, Dec 22, 2011 at 4:44 PM, Tarek Ziadé ziade.ta...@gmail.com wrote: Hey Gael's idea on using a class to define all methods for a service, gave me another idea: add a light CRUD on the top of SQLAlchemy, in Cornice For me this has nothing to do in cornice. Please keep this stuff backend independent. And if you want to do that then use a form library. Just because your model is not always (maybe never) reflecting what you want expose I post it here and now because I think it overlaps a little bit Gael's proposal The idea would be to point to Cornice an SQLAlchemy mapping and have it published as a set of RESTful APIs. Example (see the __path__ attribute): from sqlalchemy.ext.declarative import declarative_base, Column from sqlalchemy import Integer, String, Text from cornicedb import DataPublisher _Base = declarative_base() class Application(_Base, DataPublisher): __tablename__ = 'applications' __path__ = '/applications' id = Column(Integer, primary_key=True) user = Column(String(256), nullable=False) collection = Column(String(256), nullable=False) origin = Column(String(256), nullable=False) last_modified = Column(Integer, nullable=False) data = Column(Text) This would generate automatically these REST-ish URIs: - GET /applications - get the whole table, with batch options - POST /applications - adds one or several rows - DELETE /applications - adds one or several rows - GET /applications/1 - get the row of id 1 - PUT /applications/1 - updates the row of id 1 - DELETE /applications/1 - delete the row of id 1 - etc.. Other features I have in mind: - you can override or deactivate any one of these API by adding get() post() etc, methods to the class - you can write pre/post hooks, to add authentication etc - you can define what we already have in cornice (validators, etc) One pitfall: have the view and the data controller mixed in one single class. If we start to have more code atop the data, it could become a mess Cheers Tarek -- Tarek Ziadé | http://ziade.org -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: CRUD in Pyramid, using Cornice and SQLAlchemy
I'm somewhat skeptical about the usefulness of this. I have a couple of legacy apps which have been built like this - the routes tied to the database model - and came to appreciate the level of indirection added by routes. In my experience the direct relation between db objects and resources in the REST sense tends to break down once a project gets bigger. I also think that you get halfway there by using appropriate context factories for the requests. regards, robert On Thu, Dec 22, 2011 at 4:44 PM, Tarek Ziadé ziade.ta...@gmail.com wrote: Hey Gael's idea on using a class to define all methods for a service, gave me another idea: add a light CRUD on the top of SQLAlchemy, in Cornice I post it here and now because I think it overlaps a little bit Gael's proposal The idea would be to point to Cornice an SQLAlchemy mapping and have it published as a set of RESTful APIs. Example (see the __path__ attribute): from sqlalchemy.ext.declarative import declarative_base, Column from sqlalchemy import Integer, String, Text from cornicedb import DataPublisher _Base = declarative_base() class Application(_Base, DataPublisher): __tablename__ = 'applications' __path__ = '/applications' id = Column(Integer, primary_key=True) user = Column(String(256), nullable=False) collection = Column(String(256), nullable=False) origin = Column(String(256), nullable=False) last_modified = Column(Integer, nullable=False) data = Column(Text) This would generate automatically these REST-ish URIs: - GET /applications - get the whole table, with batch options - POST /applications - adds one or several rows - DELETE /applications - adds one or several rows - GET /applications/1 - get the row of id 1 - PUT /applications/1 - updates the row of id 1 - DELETE /applications/1 - delete the row of id 1 - etc.. Other features I have in mind: - you can override or deactivate any one of these API by adding get() post() etc, methods to the class - you can write pre/post hooks, to add authentication etc - you can define what we already have in cornice (validators, etc) One pitfall: have the view and the data controller mixed in one single class. If we start to have more code atop the data, it could become a mess Cheers Tarek -- Tarek Ziadé | http://ziade.org -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: CRUD in Pyramid, using Cornice and SQLAlchemy
On Thu, Dec 22, 2011 at 4:53 PM, Gael Pasgrimaud g...@gawel.org wrote: On Thu, Dec 22, 2011 at 4:44 PM, Tarek Ziadé ziade.ta...@gmail.com wrote: Hey Gael's idea on using a class to define all methods for a service, gave me another idea: add a light CRUD on the top of SQLAlchemy, in Cornice For me this has nothing to do in cornice. Please keep this stuff backend independent. I thought about building it in CorniceDB, but the layer that defines how a class describe all verbs seem to belong to Cornice. And if you want to do that then use a form library. Just because your model is not always (maybe never) reflecting what you want expose yeah maybe.. Thanks for the feedback (also thanks Robert) Cheers -- Tarek Ziadé | http://ziade.org -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Ptah 0.2 released
Hi I wanted to write to the broader community to announce we have a release which we feel can be used everyone. Ptah is a opinionated web development environment. It uses SQLAlchemy. It provides a number of features which are integrated: forms, data model, security, layouts, REST API, introspection and more. New Pyramid Users should find a environment which provides integrated technologies. Auto-generated CRUD from models, a back-end Manage User Interface. Experienced Pyramid Developers should not have any problems with Ptah. It additive. You can pick and choose which features you want. Ptah 0.2 is on pypi. Ptah is a framework. You need to use either the scaffold or one of the examples to see pixels on the screen. The examples (WSGI apps using Ptah) can be found in github: https://github.com/ptahproject/examples You can read the documentation (focus around API) readthedocs, http://ptahproject.readthedocs.org/en/latest/index.html There is a full user management package (registration, pwreset, properties, etc), ptah_crowd which has also been released. But it is not an application. Again you will need to use an example or scaffold. Ptah is in production by a number of users. And we are looking for more feedback. You can join mailing list at http://groups.google.com/group/ptahproject/ or ask questions on the pylons list. And we are on #ptahproject and #pyramid on irc.freenode.net Of current focus is enhancing documentation and building applications using Ptah. We feel we are out of the design phase. Let us know your thoughts. Happy holidays. -- Alan Runyan Skype/Twitter:: runyaga -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.