.. image:: https://media.charlesleifer.com/blog/photos/peewee3-logo.png
peewee
======
Peewee is a simple and small ORM. It has few (but expressive) concepts, making it easy to learn and intuitive to use.
* a small, expressive ORM
* python 2.7+ and 3.4+
* supports sqlite, mysql, mariadb, postgresql
* tons of `extensions <http://docs.peewee-orm.com/en/latest/peewee/playhouse.html>`_
New to peewee? These may help:
* `Quickstart <http://docs.peewee-orm.com/en/latest/peewee/quickstart.html#quickstart>`_
* `Example twitter app <http://docs.peewee-orm.com/en/latest/peewee/example.html>`_
* `Using peewee interactively <http://docs.peewee-orm.com/en/latest/peewee/interactive.html>`_
* `Models and fields <http://docs.peewee-orm.com/en/latest/peewee/models.html>`_
* `Querying <http://docs.peewee-orm.com/en/latest/peewee/querying.html>`_
* `Relationships and joins <http://docs.peewee-orm.com/en/latest/peewee/relationships.html>`_
Examples
--------
Defining models is similar to Django or SQLAlchemy:
.. code-block:: python
from peewee import *
import datetime
db = SqliteDatabase('my_database.db')
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
username = CharField(unique=True)
class Tweet(BaseModel):
user = ForeignKeyField(User, backref='tweets')
message = TextField()
created_date = DateTimeField(default=datetime.datetime.now)
is_published = BooleanField(default=True)
Connect to the database and create tables:
.. code-block:: python
db.connect()
db.create_tables([User, Tweet])
Create a few rows:
.. code-block:: python
charlie = User.create(username='charlie')
huey = User(username='huey')
huey.save()
# No need to set `is_published` or `created_date` since they
# will just use the default values we specified.
Tweet.create(user=charlie, message='My first tweet')
Queries are expressive and composable:
.. code-block:: python
# A simple query selecting a user.
User.get(User.username == 'charlie')
# Get tweets created by one of several users.
usernames = ['charlie', 'huey', 'mickey']
users = User.select().where(User.username.in_(usernames))
tweets = Tweet.select().where(Tweet.user.in_(users))
# We could accomplish the same using a JOIN:
tweets = (Tweet
.select()
.join(User)
.where(User.username.in_(usernames)))
# How many tweets were published today?
tweets_today = (Tweet
.select()
.where(
(Tweet.created_date >= datetime.date.today()) &
(Tweet.is_published == True))
.count())
# Paginate the user table and show me page 3 (users 41-60).
User.select().order_by(User.username).paginate(3, 20)
# Order users by the number of tweets they've created:
tweet_ct = fn.Count(Tweet.id)
users = (User
.select(User, tweet_ct.alias('ct'))
.join(Tweet, JOIN.LEFT_OUTER)
.group_by(User)
.order_by(tweet_ct.desc()))
# Do an atomic update (for illustrative purposes only, imagine a simple
# table for tracking a "count" associated with each URL). We don't want to
# naively get the save in two separate steps since this is prone to race
# conditions.
Counter.update(count=Counter.count + 1).where(Counter.url == request.url)
Check out the `example twitter app <http://docs.peewee-orm.com/en/latest/peewee/example.html>`_.
Learning more
-------------
Check the `documentation <http://docs.peewee-orm.com/>`_ for more examples.
Specific question? Come hang out in the #peewee channel on irc.libera.chat, or post to the mailing list, http://groups.google.com/group/peewee-orm . If you would like to report a bug, `create a new issue <https://github.com/coleifer/peewee/issues/new>`_ on GitHub.
Still want more info?
---------------------
.. image:: https://media.charlesleifer.com/blog/photos/wat.jpg
I've written a number of blog posts about building applications and web-services with peewee (and usually Flask). If you'd like to see some real-life applications that use peewee, the following resources may be useful:
* `Building a note-taking app with Flask and Peewee <https://charlesleifer.com/blog/saturday-morning-hack-a-little-note-taking-app-with-flask/>`_ as well as `Part 2 <https://charlesleifer.com/blog/saturday-morning-hacks-revisiting-the-notes-app/>`_ and `Part 3 <https://charlesleifer.com/blog/saturday-morning-hacks-adding-full-text-search-to-the-flask-note-taking-app/>`_.
* `Analytics web service built with Flask and Peewee <https://charlesleifer.com/blog/saturday-morning-hacks-building-an-analytics-app-with-flask/>`_.
* `Personalized news digest (with a boolean query parser!) <https://charlesleifer.com/blog/saturday-morning-hack-personalized-news-digest-with-boolean-query-parser/>`_.
* `Structuring Flask apps with Peewee <https://charlesleifer.com/blog/structuring-flask-apps-a-how-to-for-those-coming-from-django/>`_.
* `Creating a lastpass clone with Flask and Peewee <https://charlesleifer.com/blog/creating-a-personal-password-manager/>`_.
* `Creating a bookmarking web-service that takes screenshots of your bookmarks <https://charlesleifer.com/blog/building-bookmarking-service-python-and-phantomjs/>`_.
* `Building a pastebin, wiki and a bookmarking service using Flask and Peewee <https://charlesleifer.com/blog/dont-sweat-small-stuff-use-flask-blueprints/>`_.
* `Encrypted databases with Python and SQLCipher <https://charlesleifer.com/blog/encrypted-sqlite-databases-with-python-and-sqlcipher/>`_.
* `Dear Diary: An Encrypted, Command-Line Diary with Peewee <https://charlesleifer.com/blog/dear-diary-an-encrypted-command-line-diary-with-python/>`_.
* `Query Tree Structures in SQLite using Peewee and the Transitive Closure Extension <https://charlesleifer.com/blog/querying-tree-structures-in-sqlite-using-python-and-the-transitive-closure-extension/>`_.
Raw data
{
"_id": null,
"home_page": "https://github.com/coleifer/peewee/",
"name": "peewee",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Charles Leifer",
"author_email": "coleifer@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b4/dc/832bcf4ea5ee2ebc4ea42ef36e44a451de5d80f8b9858bf2066e30738c67/peewee-3.17.8.tar.gz",
"platform": "any",
"description": ".. image:: https://media.charlesleifer.com/blog/photos/peewee3-logo.png\n\npeewee\n======\n\nPeewee is a simple and small ORM. It has few (but expressive) concepts, making it easy to learn and intuitive to use.\n\n* a small, expressive ORM\n* python 2.7+ and 3.4+\n* supports sqlite, mysql, mariadb, postgresql\n* tons of `extensions <http://docs.peewee-orm.com/en/latest/peewee/playhouse.html>`_\n\nNew to peewee? These may help:\n\n* `Quickstart <http://docs.peewee-orm.com/en/latest/peewee/quickstart.html#quickstart>`_\n* `Example twitter app <http://docs.peewee-orm.com/en/latest/peewee/example.html>`_\n* `Using peewee interactively <http://docs.peewee-orm.com/en/latest/peewee/interactive.html>`_\n* `Models and fields <http://docs.peewee-orm.com/en/latest/peewee/models.html>`_\n* `Querying <http://docs.peewee-orm.com/en/latest/peewee/querying.html>`_\n* `Relationships and joins <http://docs.peewee-orm.com/en/latest/peewee/relationships.html>`_\n\nExamples\n--------\n\nDefining models is similar to Django or SQLAlchemy:\n\n.. code-block:: python\n\n from peewee import *\n import datetime\n\n\n db = SqliteDatabase('my_database.db')\n\n class BaseModel(Model):\n class Meta:\n database = db\n\n class User(BaseModel):\n username = CharField(unique=True)\n\n class Tweet(BaseModel):\n user = ForeignKeyField(User, backref='tweets')\n message = TextField()\n created_date = DateTimeField(default=datetime.datetime.now)\n is_published = BooleanField(default=True)\n\nConnect to the database and create tables:\n\n.. code-block:: python\n\n db.connect()\n db.create_tables([User, Tweet])\n\nCreate a few rows:\n\n.. code-block:: python\n\n charlie = User.create(username='charlie')\n huey = User(username='huey')\n huey.save()\n\n # No need to set `is_published` or `created_date` since they\n # will just use the default values we specified.\n Tweet.create(user=charlie, message='My first tweet')\n\nQueries are expressive and composable:\n\n.. code-block:: python\n\n # A simple query selecting a user.\n User.get(User.username == 'charlie')\n\n # Get tweets created by one of several users.\n usernames = ['charlie', 'huey', 'mickey']\n users = User.select().where(User.username.in_(usernames))\n tweets = Tweet.select().where(Tweet.user.in_(users))\n\n # We could accomplish the same using a JOIN:\n tweets = (Tweet\n .select()\n .join(User)\n .where(User.username.in_(usernames)))\n\n # How many tweets were published today?\n tweets_today = (Tweet\n .select()\n .where(\n (Tweet.created_date >= datetime.date.today()) &\n (Tweet.is_published == True))\n .count())\n\n # Paginate the user table and show me page 3 (users 41-60).\n User.select().order_by(User.username).paginate(3, 20)\n\n # Order users by the number of tweets they've created:\n tweet_ct = fn.Count(Tweet.id)\n users = (User\n .select(User, tweet_ct.alias('ct'))\n .join(Tweet, JOIN.LEFT_OUTER)\n .group_by(User)\n .order_by(tweet_ct.desc()))\n\n # Do an atomic update (for illustrative purposes only, imagine a simple\n # table for tracking a \"count\" associated with each URL). We don't want to\n # naively get the save in two separate steps since this is prone to race\n # conditions.\n Counter.update(count=Counter.count + 1).where(Counter.url == request.url)\n\nCheck out the `example twitter app <http://docs.peewee-orm.com/en/latest/peewee/example.html>`_.\n\nLearning more\n-------------\n\nCheck the `documentation <http://docs.peewee-orm.com/>`_ for more examples.\n\nSpecific question? Come hang out in the #peewee channel on irc.libera.chat, or post to the mailing list, http://groups.google.com/group/peewee-orm . If you would like to report a bug, `create a new issue <https://github.com/coleifer/peewee/issues/new>`_ on GitHub.\n\nStill want more info?\n---------------------\n\n.. image:: https://media.charlesleifer.com/blog/photos/wat.jpg\n\nI've written a number of blog posts about building applications and web-services with peewee (and usually Flask). If you'd like to see some real-life applications that use peewee, the following resources may be useful:\n\n* `Building a note-taking app with Flask and Peewee <https://charlesleifer.com/blog/saturday-morning-hack-a-little-note-taking-app-with-flask/>`_ as well as `Part 2 <https://charlesleifer.com/blog/saturday-morning-hacks-revisiting-the-notes-app/>`_ and `Part 3 <https://charlesleifer.com/blog/saturday-morning-hacks-adding-full-text-search-to-the-flask-note-taking-app/>`_.\n* `Analytics web service built with Flask and Peewee <https://charlesleifer.com/blog/saturday-morning-hacks-building-an-analytics-app-with-flask/>`_.\n* `Personalized news digest (with a boolean query parser!) <https://charlesleifer.com/blog/saturday-morning-hack-personalized-news-digest-with-boolean-query-parser/>`_.\n* `Structuring Flask apps with Peewee <https://charlesleifer.com/blog/structuring-flask-apps-a-how-to-for-those-coming-from-django/>`_.\n* `Creating a lastpass clone with Flask and Peewee <https://charlesleifer.com/blog/creating-a-personal-password-manager/>`_.\n* `Creating a bookmarking web-service that takes screenshots of your bookmarks <https://charlesleifer.com/blog/building-bookmarking-service-python-and-phantomjs/>`_.\n* `Building a pastebin, wiki and a bookmarking service using Flask and Peewee <https://charlesleifer.com/blog/dont-sweat-small-stuff-use-flask-blueprints/>`_.\n* `Encrypted databases with Python and SQLCipher <https://charlesleifer.com/blog/encrypted-sqlite-databases-with-python-and-sqlcipher/>`_.\n* `Dear Diary: An Encrypted, Command-Line Diary with Peewee <https://charlesleifer.com/blog/dear-diary-an-encrypted-command-line-diary-with-python/>`_.\n* `Query Tree Structures in SQLite using Peewee and the Transitive Closure Extension <https://charlesleifer.com/blog/querying-tree-structures-in-sqlite-using-python-and-the-transitive-closure-extension/>`_.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "a little orm",
"version": "3.17.8",
"project_urls": {
"Homepage": "https://github.com/coleifer/peewee/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b4dc832bcf4ea5ee2ebc4ea42ef36e44a451de5d80f8b9858bf2066e30738c67",
"md5": "e721662d3aa6d58e08d6a0ac3bde486c",
"sha256": "ce1d05db3438830b989a1b9d0d0aa4e7f6134d5f6fd57686eeaa26a3e6485a8c"
},
"downloads": -1,
"filename": "peewee-3.17.8.tar.gz",
"has_sig": false,
"md5_digest": "e721662d3aa6d58e08d6a0ac3bde486c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 948249,
"upload_time": "2024-11-12T16:58:54",
"upload_time_iso_8601": "2024-11-12T16:58:54.960178Z",
"url": "https://files.pythonhosted.org/packages/b4/dc/832bcf4ea5ee2ebc4ea42ef36e44a451de5d80f8b9858bf2066e30738c67/peewee-3.17.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-12 16:58:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "coleifer",
"github_project": "peewee",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"lcname": "peewee"
}