shazow / pyramid_scaffolds_decoupled

Decouple web-specific code from the models, libraries, and apis, so that the components can be used independently.
http://pypi.python.org/pypi/pyramid_scaffolds_decoupled
Other
3 stars 0 forks source link

An unofficial scaffolding for Pyramid. Recommended for advanced Pyramid or Pylons developers.

Contains somewhat opinionated examples that can be easily replaced.

Highlights

Usage

Install: ::

$ pip install https://github.com/shazow/pyramid_scaffolds_decoupled/tarball/master
$ pcreate --list
Available scaffolds:
  alchemy:           Pyramid SQLAlchemy project using url dispatch

-> pyramid_decoupled: Decouple web-specific code from the rest (models, library api, etc). starter: Pyramid starter project zodb: Pyramid ZODB project using traversal

Create a project: ::

$ pcreate -s pyramid_decoupled foo
$ cd foo
$ find .
./CHANGES.txt
./MANIFEST.in
./README.txt
./development.ini
./production.ini
./foo
./foo/__init__.py
./foo/lib
./foo/lib/__init__.py
./foo/lib/helpers.py           <- Available as 'h' in templates.
./foo/models
./foo/models/__init__.py       <- Unopinionated model submodule with a
./foo/models/meta.py              moderately advanced example setup.
./foo/models/objects.py
./foo/tests
./foo/tests/__init__.py
./foo/web
./foo/web/__init__.py
./foo/web/environment.py       <- Setup like routes lives here.
./foo/web/static
./foo/web/static/css
./foo/web/static/images
./foo/web/static/js
./foo/web/templates
./foo/web/templates/base.mako
./foo/web/templates/index.mako
./foo/web/views
./foo/web/views/__init__.py
./foo/web/views/index.py
./setup.cfg
./setup.py

Start the server: ::

$ python setup.py develop
... (Installs dependencies like pyramid-debugtoolbar, waitress, etc.)
$ pserve development.ini 
Starting server in PID 32481.
serving on http://0.0.0.0:5000

Suggested Structure

I'll usually build a context-insensitive API library in {{project}}/api/, so that I can do things like: ::

>>> import foo.api
>>> foo.api.account.change_password(user='foo', password='bar')
>>> r = foo.api.inventory.list(limit=20)

The api generally uses the model to do things.

This way, most of the business logic lives in the API library and is easily used by daemons, tests, or web views.

TODO