<commit_before>.. peewee documentation master file, created by
   sphinx-quickstart on Thu Nov 25 21:20:29 2010.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

.. image:: peewee-white.png

peewee
======

* a small orm
* written in python
* provides a lightweight querying interface over sql
* uses sql concepts when querying, like joins and where clauses


Examples::

    # a simple query selecting a user
    User.get(username='charles')
    
    # get the staff and super users
    editors = User.select().where(Q(is_staff=True) | Q(is_superuser=True))
    
    # get tweets by editors
    Tweet.select().where(user__in=editors)
    
    # how many active users are there?
    User.select().where(active=True).count()
    
    # paginate the user table and show me page 3 (users 41-60)
    User.select().order_by(('username', 'asc')).paginate(3, 20)
    
    # order users by number of tweets
    User.select({
        User: ['*'],
        Tweet: [Count('id', 'num_tweets')]
    }).group_by('id').join(Tweet).order_by(('num_tweets', 'desc'))


Why?
----

peewee began when I was working on a small app in flask and found myself writing<commit_msg>Adding stuff from readme to the docs index<commit_after>.. peewee documentation master file, created by
   sphinx-quickstart on Thu Nov 25 21:20:29 2010.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

.. image:: peewee-white.png

peewee
======

* a small orm
* written in python
* provides a lightweight querying interface over sql
* uses sql concepts when querying, like joins and where clauses


Examples::

    # a simple query selecting a user
    User.get(username='charles')
    
    # get the staff and super users
    editors = User.select().where(Q(is_staff=True) | Q(is_superuser=True))
    
    # get tweets by editors
    Tweet.select().where(user__in=editors)
    
    # how many active users are there?
    User.select().where(active=True).count()
    
    # paginate the user table and show me page 3 (users 41-60)
    User.select().order_by(('username', 'asc')).paginate(3, 20)
    
    # order users by number of tweets
    User.select({
        User: ['*'],
        Tweet: [Count('id', 'num_tweets')]
    }).group_by('id').join(Tweet).order_by(('num_tweets', 'desc'))


You can use django-style syntax to create select queries::

    # how many active users are there?
    User.filter(active=True).count()

    # get tweets by a specific user
    Tweet.filter(user__username='charlie')

    # get tweets by editors
    Tweet.filter(Q(user__is_staff=True) | Q(user__is_superuser=True))



Why?
----

peewee began when I was working on a small app in flask and found myself writing
{'fraction_non_alphanumeric': 0.11250447868147617, 'fraction_numerical': 0.014331780723754926, 'mean_word_length': 3.2953846153846156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3252790', 'n_tokens_mistral': 937, 'n_tokens_neox': 863, 'n_words': 299}