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.2.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for peewee_enum_field-0.2.0.tar.gz
Algorithm Hash digest
SHA256 13b4e453cd35c3e0cf5df991340c4355d614056d2a1abc00f548a37a3bb62504
MD5 99c95fe1817de8369cc87ba9301bd15b
BLAKE2b-256 7edc003bd673d0cd791925c28c6db310575a43a048a2cacfc4755e2582f993bc

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for peewee_enum_field-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28bb3aaeab9bbe639209ed8dd8673c60e04ece199eb8c6962205df6a3a28e24a
MD5 ab3f6192fdececb39b2a22ac55e53ccd
BLAKE2b-256 6c0200468507590d827a21e6f3209d72485f2110c1024adf3463c4ff41f64332

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