Skip to main content

Object wrapper for tokyo cabinet / tokyo tyrant

Project description

Tokyo cabinet and tokyo tyrant object wrapper.

Installation

$ pip install tclite

Usage

>>> import tclite as tl
>>> from datetime import datetime, date
>>> class User(tl.Model):
...     username    = tl.UnicodeProperty(key='u')  # realy stored by short 'u' key
...     birthday    = tl.DateProperty()
...     rating      = tl.IntegerProperty(default=0)
...     reply_rate  = tl.FloatProperty(default=0)
...     about_me    = tl.CompressedUnicodeProperty(internal_encoding='cp1251')
...     friends     = tl.DumpProperty(default={})
...     messages    = tl.CompressedDumpProperty(default=[])
...     is_active   = tl.BooleanProperty(default=True)
...     created     = tl.DateTimeProperty(index=True) # indexed field
...     choice      = tl.ChoiceProperty([('1', 'first'), ('2', 'second')])
...
...     __file__ = 'var/readme_test.tclite'
...     #__host__ = 'localhost:1978'
>>> User.db.clear()
>>> for i in xrange(100):
...     User(
...         username='user-%s' % i,
...         birthday=date(1900 + i, 1, 1),
...         created=datetime.now()
...     ).save()
>>> users = User.filter('birthday >=', date(1950, 1, 1))
>>> users.count()
50
>>> for user in users.filter('username endswith', '0').order('-created'):
...     user.username
u'user-90'
u'user-80'
u'user-70'
u'user-60'
u'user-50'
>>> users.get().username
u'user-50'
>>> users.delete()
>>> users.count()
0
>>> User.filter().count()
50
>>> User(username='Foo', key='user-foo').save()  # set custom key name
>>> User.get('user-foo').username  # get by keyname
u'Foo'

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

tclite-0.33.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file tclite-0.33.tar.gz.

File metadata

  • Download URL: tclite-0.33.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tclite-0.33.tar.gz
Algorithm Hash digest
SHA256 fe4b43696624cd5fd00dfed1fd9b80ac9bcf737d6157e561dc912d361079ee6e
MD5 4453c797d3abe06e014d5733dcc76c42
BLAKE2b-256 a340757d6d178df4ebe90ae4d6cde94ea328cfca2629369ae739cd086fc5b9bd

See more details on using hashes here.

Supported by

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