Versioned Objects
A versioned object is a specialized data container, capable of representing data when the schema for that data has gone through several different revisions. This is useful when loading data from a data store which may have older versions of the data, such as a file or a database.
To declare a versioned class, create a class extending VObject; then, declare one or more Schema classes within that class, i.e.:
class Employee(VObject):
class Version1(Schema):
__version__ = 1
first = Attribute()
last = Attribute()
salary = Attribute(0, validate=int)
To create a new object of this class, simply pass keyword arguments to the constructor matching the attributes:
>>> worker = Employee(first='Kevin', last='Mitchell', salary=15)
The data is available as attributes of the object:
>>> worker.first 'Kevin' >>> worker.salary 15
Eventually, you will discover changes that need to be made to this schema, such as the fact that some cultures do not use first or last names. To alter the schema for this, we’ll create a new “name” attribute and drop the “first” and “last” attributes. We also need an upgrader to convert values from the old schema to the new:
class Employee(VObject):
class Version1(Schema):
__version__ = 1
first = Attribute()
last = Attribute()
salary = Attribute(0, validate=int)
class Version2(Version1):
# __version__ is automatically incremented here, but you
# can set it explicitly
name = Attribute()
# salary is inherited, but so are first and last, so we
# need to mask them...
first = None
last = None
# And we need an upgrader...
@upgrader
def _upgrade_from_1(cls, state):
state['name'] = '%s %s' % (state['first'], state['last'])
del state['first']
del state['last']
return state
Versioned objects implement the pickle protocol, so that they can be pickled and unpickled. The pickle protocol implementation allows older versions of the object to be converted into the newer version. It is also possible to convert versioned objects directly to and from dictionaries, allowing any serialization mechanism to be used.
Metadata
Release files for vobj 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vobj-0.2.0.tar.gz | 23.5 kB | Without provenance | Details for vobj-0.2.0.tar.gz |
Release files / vobj-0.2.0.tar.gz
| Download URL | vobj-0.2.0.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a9f72dc3df780ccaac372d1144928f5818b9c934fe398231aeb888d7376ae5d
|
|
BLAKE2b-256 checksum How to use checksums |
cb683a0ce30cb591f5a5f854541795747808cdacbdfad63e73f45abd67f4969c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for vobj 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.