Skip to main content

`fieldprop` provides a decorator `@field` like a property. A `field` object has `getter`, `setter`, `delete`, `validator`, `packer` and `unpacker` methods. It is primary intended to use to define a model class associated with a database table.

Project description

fieldprop

fieldprop provides a decorator @field like the property. A field object has getter, setter, delete, validator, packer and unpacker methods. It is primary intended to use to define a model class associated with a database table.

Usage

Following is a simple example.

from fieldprop import field
from fieldprop.exceptions import ValidationError

class Foo(object):
	def __init__(self):
		self._username = None

	@field('User name')
	def username(self):
		return self._username

	@username.setter
	def username(self, v):
		self._username = v

	@username.validator
	def username(self):
		if self._username is None:
			raise ValidationError('User name is required.')

	@username.packer
	def username(self):
		return self._username.encode('utf-8')

	@username.unpacker
	def username(self, v):
		self._username = str(v, 'utf-8')

getter and setter are same as the properity. Additionary, validator can be defined to validate the field value.

packer/unpacker are intended for saving field value to database. You can implement data conversion in packer/unpacker.

LICENSE

This software is released under the MIT license, see LICENSE.

Project details


Download files

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

Files for fieldprop, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size fieldprop-1.0-py3-none-any.whl (5.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size fieldprop-1.0.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page