Skip to main content

MyNoSQL

Project description

MyNoSQL

The MyNoSQL Module provides a distributed no-sql database library that is intended to be embedded into python applications. It allows fast local reading and writing of records, taking care of data replication for you regardless of the reliability of your network connection.

By using a MyNoSQL database you are freed from needing to worry about ensuring data gets to where it need to go or handling errors related to bad network connections.

  • You write to the database locally knowing MyNoSQL will take care of ensuring eventually it will be replicated to the mirror in the background, you don't need to wait for that to happen in your application.
  • You make a local read request and MyNoSQL will return the document as quickly as possible, taking care of caching and only requesting the document from the remote mirror if it's changed

The MyNoSQL database will be respectful of your machine resources and will not waste them unnecessarily:

  • Records are purged from ram when no longer in use
  • All data stored on disk is compressed with LZMA compression to minimise disk usage -Records are not stored as individual files but in a shard of files, allowing each shard to grow and use a whole block on a disk, reducing the number of partially used blocks (wasted space on a disk).
  • Network traffic is minimised by only transferring records when they change. This is done via a record index that tracks the revisions of all documents, MyNoSQL databases request each other's indexes and update their own index when there is a newer record. This allows MyNoSQL to know if the local copy of a record is current and can be returned immediately or if a newer version need to be downloaded.

While there is no limit to applications that could use MyNoSQL, here are some example applications where MyNoSQL's features could be valuable:

  • IoT data logging with central data storage, each data logger would be a peer, with your central location having 1 or more mirrors. The data logging application would write to the local peer database allowing your data logging application to continue with it's data logging activities and the MyNoSQL will replicate the logged data to the mirror(s) in the background when connectivity is available
  • Multiplayer games, implementing MyNoSQL in a multiplayer game would allow the game developer to significantly reduce the load on their game servers as game clients running a peer replica of the game database would only need to download game resources as they change and would only poll the game server for the a single index update rather than polling every resource to determine if the resource has changed or worse yet downloading every resource if caching is not implemented. Additionally implementing MyNoSQL allows the player to continue playing and save gameplay state even when their internet connection is lost without the game developer needing to handle these scenarios, MyNoSQL will update the save states to the game server when the internet connection is restored.
  • Block chains, MyNoSQL could make development of a block chain simpler, the block chain application only need to worry about reading, writing and validating block records.

Using this module

First import the module and create a database instance

import MyNoSQL

db = MyNoSQL.MyNoSQL()
db.opendb("YourDatabseName")

Changing database mode

The default mode for a MyNoSQL is peer, you will need at least one mirror, typically this is your application server. When your MyNoSQL instance is it's mode changed, the new mode is remembered, so this only needs to be called once, not every time the application is launched.

db.setdbmode("Mirror")  # optional

Connecting to a database mirror

In order for database replication to happen, either remote storage of records or retrieving of records created you will need to connect to a mirror, you don't need to connect to multiple mirrors though as once connected to the first mirror a list of all available mirrors is retrieved and stored locally, so this only needs to be called once, not every time the application is launched.

db.addpeer("http://mirrorhostname:8800")

Saving a record

MyNoSQL records are simply a python dictionary object, anything that can be stored in a python dictionary can be stored in a MyNoSQL record.

The following are reserved dictionary keys:

  • id: the record id, you can set this to any value you wish, if you do not provide an id then one will be generated on first save. If you change the record id then it will be treated as a new record.
  • rev: the recored revision, this will be created if not provided or in an invalid format, and incremented if one is provided, however the record will not be saved if there is a later revision for the same record id. You should always check you have the latest revision of a record before updating it.

Saving a record is as simple as:

myrecord = db.savedoc(myrecord)

The returned record contains the generated id if you did not provide one and the updated record revision.

Reading a record

Reading a record is as simple as:

myrecord = db.readdoc(myrecordid)
  • If the record's latest revision is available locally it will be returned immediately
  • if the record's latest revision is not available locally, it would be downloaded then returned

DB Modes

MyNoSQL has modes of operation, Peer (Default) and Mirror

Peer

A Peer, will cache documents requested or written by the local application, it will not keep copies of documents the the local local application has not interacted with

When a MyNoSQL database in peer mode:

  • Writing a new record MyNoSQL will:
    • write locally
    • contact a mirror and replicate to that mirror
  • when reading a record MyNoSQL will:
    • check if the most recent version of the record is available locally
    • request the most recent version of the record from a mirror if not available locally
    • return the most recent version of the record
  • periodically poll a mirror to push any local records that are newer then the record version on the mirror

Mirror

A mirror, will attempt to keep copies of all documents.

When a MyNoSQL database in mirror mode:

  • Receive records from peers and mirrors
    • write the received record
  • Receive requests for records from peers and mirrors
    • read the record and return to the requestor
  • Writing a new record MyNoSQL will:
    • write locally
    • attempt to contact all mirrors and replicate to those mirrors
  • When reading a record MyNoSQL will:
    • check if the most recent version of the record is available locally
    • if not available locally request the most recent version of the record from each mirror until a mirror provides the record requested (This should rarely happen as mirrors should already have received the record when it was written on another mirror, or through periodical polling)
    • return the most recent version of the record
  • periodically poll all other mirrors to check the versions of records and request updates to any records that are out of date

Installing

pip3 install -U MyNoSQL

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

MyNoSQL-0.0.6.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

MyNoSQL-0.0.6-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file MyNoSQL-0.0.6.tar.gz.

File metadata

  • Download URL: MyNoSQL-0.0.6.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.10

File hashes

Hashes for MyNoSQL-0.0.6.tar.gz
Algorithm Hash digest
SHA256 6f7e53da33b5236f0e382a078f20d1b7ae0a69c92da7d9a7d571914a026a5e81
MD5 bc4d23587bbdf440938058fdaf7a142a
BLAKE2b-256 b0931d336e8dc57b90f5628915ae826978322ef5cfa5071a972b9c66f65bd911

See more details on using hashes here.

File details

Details for the file MyNoSQL-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: MyNoSQL-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.10

File hashes

Hashes for MyNoSQL-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1bf82f4dbd1a2d357218662111b5b950bc6c62e54880ef8cef4db3a1b403dbfa
MD5 f9634904dd3be867524d46fe98c8efca
BLAKE2b-256 69982667a2614ba359576c8171cf8952bb2dbda60506f33ff8056a3cc393b452

See more details on using hashes here.

Supported by

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