Package: pyramid-peewee-conn
OverviewA package which provides integration between the Pyramid web application server and
the peewee ORM.It’s tested under CPython 3.4 but maybe run under any environ which pyramid and peewee can be used.
If you found any issue in using it, pleasesubmit it.InstallationInstall using setuptools, e.g. (within a virtual environment):$ easy_install pyramid_peewee_connOr using pip:$ pip install pyramid_peewee_connOr install from github:$ git clone https://github.com/inpool/pyramid_peewee_conn
$ cd pyramid_peewee_conn
$ python setup.py installOr if your computer hasn’t git command, you can install it via from github:$ pip install https://github.com/inpool/pyramid_peewee_conn/archive/master.zipSetupOncepyramid_peewee_connis installed, you must use theconfig.includemechanism to include it into your Pyramid project’s configuration.  In your
Pyramid project’s__init__.py:config=Configurator(.....)config.include('pyramid_peewee_conn')Alternately you can use thepyramid.includesconfiguration value in your.inifile:[app:myapp]pyramid.includes=pyramid_peewee_connUsingForpyramid_peewee_connto work properly, you must add at least one
setting to your of your Pyramid’s.inifile configuration (or to thesettingsdictionary if you’re not using ini configuration):peewee.urls.  For example:[app:myapp]# ...peewee.url=postgres://username:password@hostname:port/database_name# ...Thepeewee.urlparameter is a URL defined in the peewee documentationConnecting using a Database URLOnce you’ve both included thepyramid_peewee_conninto your configuration
viaconfig.include('pyramid_peewee_conn')and you’ve added apeewee.urlsetting to your configuration, you can then use thepyramid_peewee_conn.get_db()API in your Pyramid application, most
commonly in a model defintion:frompeeweeimport*frompyramid_peewee_connimportget_dbdb=get_db()classPerson(Model):name=CharField()age=IntegerField()classMeta:database=dbclassPet(Model)name=CharField()owner=ForeignKeyField(Person,related_name='pets')animal_type=CharField()db.connect()db.create_tables([Person,Pet])Thepyramid_peewee_conn.get_db()API returns a peewee.Database instance which
you’ve specified viapeewee.urlin your configuration.AttentionSince the peewee database url is configure in ini file, the APIpyramid_peewee_conn.get_db()must use after the instance ofpyramid.config.Configuratorhas been created and this package
has been included. In other words, if you configure this package via ini file like this:[app:myapp]# ...pyramid.includes=pyramid_peewee_conn# ...You can usepyramid_peewee_conn.get_db()after the instance ofpyramid.config.Configuratorhas been created. if you configure this package imperatively, you must usepyramid_peewee_conn.get_db()after thepyramid.config.Configurator.include()method has called by pass‘pyramid_peewee_conn’.frompyramid.configimportConfiguratordefmain(global_config,**settings):config=Configurator(settings=settings)# Now you can use get_db() if you configure this package in ini file.config.include('pyramid_peewee_conn')# Or you can use get_db() at this time.Delay InitializtionThere are some cases that need use the database before thepyramid.config.Configuratorhas
been instantiated. For example, a Model class is the configurator’s root_factory, or by any
reason of, you need import the models in the__init__.pyfile.In these cases, you can usepyramid_peewee_conn.get_proxy()instead ofpyramid_peewee_conn.get_db(), the parameters ofget_proxy()is as same asget_db().Thepyramid_peewee_conn.get_proxy()returns anpeewee.Proxyinstance which will initialize
automatically at that time whenpyramid.config.Configuratorinclude this package.Now, you can use peewee database before thepyramid.config.Configuratorhas been instantiated.
But you can’t do any database opration beforepyramid.config.Configuratorhas been instantiated.NoteThe proxy whichpyramid_peewee_conn.get_proxy()will never initialize except this package
was included next time or callpyramid_peewee_conn.init_proxies()explicit. You can get more
information in the API’s docstring.Named DatabasesIf you need to use more than one database in your Pyramid application,
you can usenameddatabases via configuration.  Named databases are
specified bypeewee.url.thenamein settings configuration.  For
example:[app:myapp]# ...peewee.url=postgres://username:password@hostname:port/database_namepeewee.url.memory=sqlite:///:memory:# ...Once this is done, you can usepyramid_peewee_conn.get_db()to
obtain a reference to each of the named databases:db=get_db()# main databasememory_db=get_db('memory')Thepeewee.url.memoryparameter example above is a URL which
describes peewee database, in the same format aspeewee.url.  You can
combine named and unnamed database configuration in the same application.
You can also use named databases without a main database.Another config formatPerhaps you had used pyramid_peewee, which configpeewee.urlsin the ini configure file like this:[app:myapp]# ...peewee.urls=postgres://username:password@hostname:port/database_1sqlite:///test.db# ...This config format is supported. In this case, the database name is the database name.
The prior configuration is equal to the next:[app:myapp]# ...peewee.url=postgres://username:password@hostname:port/database_1peewee.url.database_1=postgres://username:password@hostname:port/database_1peewee.url.test.db=sqlite:///test.db# ...APIsThis package offer three API:pyramid_peewee_conn.get_db()pyramid_peewee_conn.get_proxy()pyramid_peewee_conn.init_proxies()The usage of these function you can found in there own’s docstring via builtinhelp(obj).If you found there were more functions or classes else in the souce code, it maybe changed in future.ConflictOnce there are both two format configure and have some database conflict,
the explicit configuration will be used.[app:myapp]# ...peewee.url=postgres://user:pass@host:port/databasepeewee.url.db1=mysql://user:pass@host:port/databasepeewee.urls=mysql://user:pass@host:port/db1postgres://user:pass@host:port/database# ...The prior configuration is equal next:[app:myapp]# ...peewee.url=postgres://user:pass@host:port/databasepeewee.url.db1=mysql://user:pass@host:port/databasepeewee.url.database=postgres://user:pass@host:port/database# ...Change Log0.7.1Just change the description.0.7.0Add APIget_proxy()and it’s documentationAdd APIinit_proxies()and it’s documentationAdd unit test for the new APIs0.6.3Fix a bug with old_style database urls.0.6.2Fix formats of README and Changelog.0.6.1Complete unit test.Unit test each API separate into 3 cases.Add multiple installation methods in README.rstFix bug when include more than once(Offen in unit test).0.6.0Add unit test.Fix0.5.2Fix. Report a CHANGES.txt can’t be found error.0.5.1Fix. README.rst has some format error.0.1.0Initial version