Skip to main content

A custom EnumField for Peewee ORM to handle Python Enum types.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peewee_enum_field-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

peewee_enum_field-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file peewee_enum_field-0.1.0.tar.gz.

File metadata

  • Download URL: peewee_enum_field-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for peewee_enum_field-0.1.0.tar.gz
Algorithm Hash digest
SHA256 77239a02aa0caefe0ab773cbd1648b5c91340bafdf53534eee9ecf6f43404718
MD5 a347ea104f2a852ef9e4f03237b9c87e
BLAKE2b-256 452325951c89a39189c9dda5ba7d288c4185ec2deab275e49d88af94fcf7393a

See more details on using hashes here.

File details

Details for the file peewee_enum_field-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: peewee_enum_field-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for peewee_enum_field-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d25ce6ff529a041df029c3b1b401d84efaaef4a8fdf7133c0c0af241d68cbeac
MD5 5dadddd278fe5a4ed5f036d1528436f4
BLAKE2b-256 98a4b5bc2742e865e5da11d9672c19887288e26af92d89af929d55d933e1761f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page