pyramid_peewee
Pyramid_peewee is a module for the Pyramid web application framework which allos developers to use Peewee as their ORM.
Requirements:
1. Pyramid 2. Peewee 3. Database
Usage:
Typically Pyramid based applications are configured in two locations, at the application level within the application __init__.py file and at the instance level within an “ini” file, such as production.ini. To configure your applicaiton, first at the instance (eg production.ini) level you must set peewee.urls = “database connection url”
peewee.urls = sqlite:///dbase.db
or
peewee.urls =
postgresql://user:pass@localhost:5432/mydatabase
sqlite:///dbase.db
Note we specifically use database urls as defined in the peewee documentation Connecting using a Database URL and that you may specify as many database urls as your application needs within the peewee.urls paramter. At the application level, eg within your applications __init__.py file
import your database model
include the command config.include(‘pyramid_peewee’) within the config section.
Define your data model: To define your data model fist set your database = peewee.Proxy. Note if your database contains a “.” in the name, such as with sqlite files replace it with an “_” (underscore).
from peewee import *
mydatabase = Proxy()
dbase_db = Proxy()
class People(Model):
name = TextField()
class Meta:
database = mydatabase
class Cars(model):
name = TextField()
class Meta:
database = dbase_db
In this example we’ve defined two tables, each derived from different database Proxies. Peewee allows you to define as many database connections as you need and utilize them seemlessly within an application.
Using your datamodel within a View:
To utilize your datamodel within a view you must first get a datbase connection. This is accomplished by calling the database proxy which is tied to the view request. By doing so database connections are properly closed as the end of the request.
from model import *
def myView(requset):
request.mydatabase
joe = People.select().where(People.name=='joe').get()
return dict(name=joe.name)
As stated above by calling request.mydatabase two things are accomplished, one a database connection is opened for the request, and two a callback is registered wich will properly close the connection at the end of the request. Trying to use the model without first calling the database method from the request object will result in an DataBaseClosed error. This is a devation from the normal PeeWee behavior which normaly opens a connection as needed.
Supported database urls from the PeeWee documentation:
sqlite:///my_database.db will create a SqliteDatabase instance for the file my_database.db in the current directory.
sqlite:///:memory: will create an in-memory SqliteDatabase instance.
postgresql://postgres:my_password@localhost:5432/my_database will create a PostgresqlDatabase instance. A username and password are provided, as well as the host and port to connect to.
mysql://user:passwd@ip:port/my_db will create a MySQLDatabase instance for the local MySQL database my_db.
Supported schemes:
apsw: APSWDatabase
mysql: MySQLDatabase
mysql+pool: PooledMySQLDatabase
postgres: PostgresqlDatabase
postgres+pool: PooledPostgresqlDatabase
postgresext: PostgresqlExtDatabase
postgresext+pool: PooledPostgresqlExtDatabase
sqlite: SqliteDatabase
sqliteext: SqliteExtDatabase
The most up to date documentation can always be found on their website: Peewee Database URL
Metadata
Release files for pyramid_peewee 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyramid_peewee-0.5.tar.gz | 5.0 kB | Without provenance | Details for pyramid_peewee-0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyramid_peewee-0.5-py3-none-any.whl | Python 3 | none | any | Details for pyramid_peewee-0.5-py3-none-any.whl |
Total release size: 13.1 kB
Release files / pyramid_peewee-0.5.tar.gz
| Download URL | pyramid_peewee-0.5.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
497d54bb22065389ba5b8727e6195d3ad5319ad98aa566bf7aa38d4e76cc3c4d
|
|
BLAKE2b-256 checksum How to use checksums |
7f66979a5bf94f5bc0ab606d7ae0628f28a39afd4b71caf4a119f16ab8fb4c3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pyramid_peewee-0.5-py3-none-any.whl
| Download URL | pyramid_peewee-0.5-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c3adf6e7c4bbffb99485142209314f2e3d19da09b4572f7cd4a816e463304a5
|
|
BLAKE2b-256 checksum How to use checksums |
328012fda8e896955a0f7ff81176a1ae879b28a3b66248be662dd91132cf933a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pyramid_peewee 0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.