
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
tinydb-serialization
Advanced tools
tinydb-serialization ^^^^^^^^^^^^^^^^^^^^
|Build Status| |Coverage| |Version|
tinydb-serialization provides serialization for objects that TinyDB
otherwise couldn't handle.
Usage
To use a serializer, create a SerializationMiddleware instance with
the storage class you want to use and register the serializers you want
to use. Then you pass the middleware instance as the storage to TinyDB:
.. code-block:: python
>>> from tinydb import TinyDB, Query
>>> from tinydb.storages import JSONStorage
>>> from tinydb_serialization import SerializationMiddleware
>>> from tinydb_serialization.serializers import DateTimeSerializer
>>>
>>> from datetime import datetime
>>>
>>> serialization = SerializationMiddleware(JSONStorage)
>>> serialization.register_serializer(DateTimeSerializer(), 'TinyDate')
>>>
>>> db = TinyDB('db.json', storage=serialization)
>>> db.insert({'date': datetime(2000, 1, 1, 12, 0, 0)})
>>> db.all()
[{'date': datetime.datetime(2000, 1, 1, 12, 0)}]
>>> query = Query()
>>> db.insert({'date': datetime(2010, 1, 1, 12, 0, 0)})
>>> db.search(query.date > datetime(2005, 1, 1))
[{'date': datetime.datetime(2010, 1, 1, 12, 0)}]
Important: A SerializationMiddleware instance always wraps a database's storage.
This means that the SerializationMiddleware instance cannot be shared
between multiple TinyDB instances as they would use the same underlying storage
instance and thus share all data between both instances.
tinydb_serialization.serializers.DateTimeSerializer: serializes datetime objects
as ISO 8601 formatted stringstinydb_serialization.serializers.DateSerializer: serializes date objects
as ISO 8601 formatted stringsIn this example we implement a serializer for datetime objects (like the one provided
by this package):
.. code-block:: python
from datetime import datetime
from tinydb_serialization import Serializer
class DateTimeSerializer(Serializer):
OBJ_CLASS = datetime # The class this serializer handles
def encode(self, obj):
return obj.isoformat()
def decode(self, s):
return datetime.fromisoformat(s)
Changelog
DateSerializer in this package (see issue #16 <https://github.com/msiemens/tinydb-serialization/pull/16>_)pull request #14 <https://github.com/msiemens/tinydb-serialization/pull/14>_)pull request #17 <https://github.com/msiemens/tinydb-serialization/pull/17>_)DateTimeSerializer in this package (see issue #10 <https://github.com/msiemens/tinydb-serialization/pull/10>_)pull request #9 <https://github.com/msiemens/tinydb-serialization/pull/9>_)pull request #5 <https://github.com/msiemens/tinydb-serialization/pull/5>_)pull request #3 <https://github.com/msiemens/tinydb-serialization/pull/3>_)pull request #2 <https://github.com/msiemens/tinydb-serialization/pull/2>_)issue #1 <https://github.com/msiemens/tinydb-serialization/issues/1>_).. |Build Status| image:: https://img.shields.io/github/workflow/status/msiemens/tinydb-serialization/Python%20CI?style=flat-square :target: https://github.com/msiemens/tinydb-serialization/actions?query=workflow%3A%22Python+CI%22 .. |Coverage| image:: https://img.shields.io/coveralls/msiemens/tinydb-serialization.svg?style=flat-square :target: https://coveralls.io/r/msiemens/tinydb-serialization .. |Version| image:: https://img.shields.io/pypi/v/tinydb-serialization.svg?style=flat-square :target: https://pypi.python.org/pypi/tinydb-serialization/
FAQs
Serialization for objects that TinyDB otherwise couldn't handle
We found that tinydb-serialization demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.