Skip to main content
https://img.shields.io/pypi/v/peewee2click.svg https://img.shields.io/pypi/pyversions/peewee2click.svg https://travis-ci.org/buguroo/peewee2click.svg?branch=master

peewee2click is an easy to use Click helper to create command-line CRUDL interfaces for your peewee models.

What are command-line CRUDL interfaces?

Interfaces that let you Create, Read, Update, Delete or List your models via command-line.

Installation

Just run pip install peewee2click.

Example of use

Let supose you have the following peewee class:

import peewee

class MyClass(peewee.Model):
    my_char_field = peewee.CharField(
        max_length=8, help_text="Field to store char.")
    my_int_field = peewee.IntegerField(
        default=5, help_text="Field to store int.")

To create a very basic command-line CRUDL you only need the following code:

from peewee2click import CRUDL
import click

@click.command(help="Creates a new myclass")
@CRUDL.click_options_from_model_fields(MyClass)
def create(**fields):
    CRUDL.create(MyClass, **fields)

@click.command(help="Shows myclass information")
@click.argument("primary_key", type=int)
def show(primary_key):
    CRUDL.show(MyClass, primary_key)

@click.command(help="Updates myclass information")
@click.argument("primary_key")
@CRUDL.click_options_from_model_fields(MyClass)
def update(primary_key, **changed_fields):
    CRUDL.update(MyClass, primary_key, **changed_fields)

@click.command(help="Deletes an existing myclass")
@click.argument("primary_key")
def delete(primary_key):
    CRUDL.delete(MyClass, primary_key)

@click.command("list", help="Enumerate myclasses")
@click.option("fields", "--add-field", multiple=True,
              help="Shows a custom field in the result")
def list_(fields):
    base_fields = ('id', 'my_char_field', 'my_int_field')

    CRUDL.list(MyClass, base_fields, extra_fields=fields)

As you can see, CRUDL.click_options_from_model_fields gathers all the Model fields for you, creating automatically the parameters options “--my-char-field=<new_value>” and “-my-int-field=<new_value>” for the create and update commands.

Other commands

Besides the CRUDL methods seen in the example above, peewee2click also provides two helper functions: one_and_only_one and max_one. Both provide a way of checking that arguments are passed in a proper way.

Check the docstrings of the functions for further information.

Running the tests

Install the develop dependencies: pip install -e requirements/develop.txt. Then run tox.

You will need sqlite support in your Python client to run the tests.

Metadata

Release files for peewee2click 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for peewee2click 0.0.4
File Size Uploaded
peewee2click-0.0.4.tar.gz 5.2 kB Details

Release files / peewee2click-0.0.4.tar.gz

Download URL peewee2click-0.0.4.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7f5b5beb426ac1aea41d5fa3852a104bc45f70e2ab1fcf65191b243b248b82ff
BLAKE2b-256 checksum
How to use checksums
e3e48147b6c0d94a40ce93e4e1cbf71b1352b3251a49d8bfc73c9cac27d12d4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page