peewee-enum-field
A custom field for Peewee, a small, expressive ORM, that allows for the easy integration of Python Enums in Peewee models.
Overview
peewee-enum-field provides a convenient way to store Python Enum types in a Peewee database. This custom field stores the name of an Enum member as a string in the database and handles automatic conversion between the Enum type and the string representation when reading or writing to the database.
Installation
To install peewee-enum-field, you can use pip:
pip install peewee-enum-field
Usage
from enum import Enum
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
Then, use EnumField in your Peewee model:
import peewee
from peewee_enum_field import EnumField
class MyModel(peewee.Model):
color = EnumField(Color)
You can now assign Enum members to the field, filter, etc:
instance = MyModel.create(color=Color.RED)
instance = MyModel.get(Color.color == Color.RED)
The field automatically handles conversion to and from the Enum type:
assert instance.color == Color.RED
Features
- Easy integration with Peewee models.
- Stores the name of the Enum member in the database for readability.
- Automatically converts to and from the Python Enum type.
Requirements
- Python 3.6+
- Peewee
License
peewee-enum-field is released under the MIT License.
Metadata
Release files for peewee-enum-field 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| peewee_enum_field-0.2.0.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| peewee_enum_field-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.4 kB
Release files / peewee_enum_field-0.2.0.tar.gz
| Download URL | peewee_enum_field-0.2.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13b4e453cd35c3e0cf5df991340c4355d614056d2a1abc00f548a37a3bb62504
|
|
BLAKE2b-256 checksum How to use checksums |
7edc003bd673d0cd791925c28c6db310575a43a048a2cacfc4755e2582f993bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.5 Linux/5.15.153.1-microsoft-standard-WSL2
|
Release files / peewee_enum_field-0.2.0-py3-none-any.whl
| Download URL | peewee_enum_field-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28bb3aaeab9bbe639209ed8dd8673c60e04ece199eb8c6962205df6a3a28e24a
|
|
BLAKE2b-256 checksum How to use checksums |
6c0200468507590d827a21e6f3209d72485f2110c1024adf3463c4ff41f64332
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.5 Linux/5.15.153.1-microsoft-standard-WSL2
|