peewee2click: Easy command-line interfaces for Peewee models
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| peewee2click-0.0.4.tar.gz | 5.2 kB | Without provenance | Details for peewee2click-0.0.4.tar.gz |
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 |
Security for peewee2click 0.0.4
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.