Skip to main content

A Python library for NoSQL record versioning.

Installation

To install the latest release on PyPi, simply run:

pip install nosql_versioning

Or to install the latest development version, run:

git clone https://github.com/xinhuang/nosql_versioning.git
cd nosql_versioning
python setup.py install

Quick Tutorial

>>> from nosql_versioning import schema
>>> import json
>>>
>>> version, Record = schema(decode=json.loads)
>>>
>>> @version()
>>> class Recordv0(object):
>>>     def __init__(self, data):
>>>         self.old_name = data['old_name']
>>>
>>> @version(1)
>>> class Recordv1(object):
>>>     def __init__(self, value=None, *args, data=None):
>>>         if data:
>>>             self.new_name = data['new_name']
>>>         else:
>>>             self.new_name = value
>>>
>>>     @staticmethod
>>>     def migrate(data):
>>>         data['new_name'] = data['old_name']
>>>         del data['old_name']
>>>
>>>     @staticmethod
>>>     def a_staticmethod(n):
>>>         print(n * 2)
>>>
>>> rec = Record('{"_ver": 0, "old_name": 1}')
>>> print(rec.new_name)
1
>>> rec = Record(value=42)         # custom constructor can also be used
>>> print(rec.new_name)
42
>>> Record.a_staticmethod(42)      # static methods defined in the latest version can be used
84

API Reference

schema(decode=decode, version=get_version)

Create a class descriptor to specify record classes of different version, and a Record initializer to instantiate the latest record from data, or to migrate data to the latest version.

Args:
  • decode: Deserialize objects retrieved from database. By default no decoding will be applied.

  • version: Get version from record. By default it’s data.get('_ver')

Returns:
  • version: A class descriptor to specify record version.

  • Record: A initializer that to construct defined Record class. Migrate if data is not the latest version.

version(n=0)

A class descriptor to specify record class of version N.

Args:
  • n: Version. Must be a integer.

Raises:
  • VersionConflictionException: When a version is defined twice.

Record(data=None, *args, **kwargs)

The initializer to migrate record to latest and instantiate record class.

Args:
  • data: If only this argument is specified, decode(data) will be used to instantiate the latest record class. (Migrate if needed.)

  • args, kwargs: If not only data is specified, all arguments will be passed to instantiate the latest record class. No migration.

Migration from Version N-1 to N will use static method migrate in record class version N.

In case there is no version specified, migration from None to 0 will use static method migrate in record class Version 0.

Licensing

This project is released under the terms of the MIT Open Source License. View LICENSE.txt for more information.

Metadata

Release files for nosql-versioning 0.1.8.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for nosql-versioning 0.1.8.3
File Interpreter ABI Platform
nosql_versioning-0.1.8.3-py3-none-any.whl Python 3 none any Details

Release files / nosql_versioning-0.1.8.3-py3-none-any.whl

Download URL nosql_versioning-0.1.8.3-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60e41e3369728da61c9da4eff68f68e5f7a8fa750377477da28c2d6dc2c0224e
BLAKE2b-256 checksum
How to use checksums
d13d81735b70d51528a42cd901e50e5adbd849c08ef0153d2c72266e2223718a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.8.3 This release

1 release file

0.1.8.2

1 release file

0.1.8.1

1 release file

0.1.8.0

1 release file

0.1.7.1

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5.1

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page