PyMDict
Advanced Python Mongo Dict. A Python dictionary based on a MongoDB. It allows to treat a collection as a dictionary in Python, with extensive capabilities, like allowing basic queries, bulk operations and versioning (forks).
INSTALLATION
Currently it is only supported Python3.4 onwards. It can be installed through pip:
$ pip3 install pymdict
USAGE
In order to run, a MongoDB server is required.
A Mongo-based dictionary can be instantiated as follows:
>>> from pymdict.mongo_dict import MongoDict
>>>
>>> m = MongoDict("custom_id", mongo_host="localhost", mongo_port=27017)
Once m is instantiated, it can be used as a normal dictionary.
>>> m["key"] = "value"
>>> m[44] = "value2"
>>> m["key2"] = "value3"
>>> m["number"] = 44
>>> print(list(m.keys()))
["key", 44, "key2, "number"]
>>> for key, value in m.items():
... print("{}: {}".format(key, value))
key: value
44: value2
key2: value3
number: 44
In addition, there are advanced functionalities like queries:
>>> for key, value, _ in m('key % ey'):
... print("{}: {}".format(key, value))
key: value
key2: value3
>>> for key, value, _ in m('key % ey or value = 44'):
... print("{}: {}".format(key, value))
key: value
key2: value3
number: 44
Queries also support to query with sub-dict elements:
>>> m["first"] = {"example": 44}
>>> m["second"] = {"example": 45}
>>> m["third"] = {"example": 46}
>>> for key, value, _ in m('value.example > 44 and value.example < 46'):
... print("{}: {}".format(key, value))
second: 45
(TODO: Check the wiki page for more information about the query syntax)
Note that all the stores and removals are stored within a MongoDB. This means for each addition,edit and removal there is at least one connection to the MongoDB backend. In order to optimize it, a bulk operation can be used to wrap such amount of operations in a single connection:
>>> with m.bulk(buffer_size=100) as m:
... for x in range(2000):
... m["key{}".format(x)] = {"example": x}
Also, a mongo dict can be forked without the need to copy its content. This is specially useful if the target dict is extremely big and a copy is wanted. Note that a fork is an immediate process, and it allows to override or remove elements without modifying an original dictionary. It is achieved by applying a versioning technique with the dictionaries and it is still in an experimental state.
(TODO: More information about forking and versioning in the wiki page)
>>> m['foo'] = "bar"
>>> fork = m.fork()
>>> print(fork['foo'])
bar
>>> fork['foo'] = "foo"
>>> print(fork['foo'], m['foo'])
foo bar
Metadata
Release files for pymdict 0.0.4
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 |
|---|---|---|---|---|
| pymdict-0.0.4.tar.gz | 15.1 kB | Without provenance | Details for pymdict-0.0.4.tar.gz |
Release files / pymdict-0.0.4.tar.gz
| Download URL | pymdict-0.0.4.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7b5df2bacef92546aa4523516292d6d846e3a0c0206c6f2ede971e02ec6f889
|
|
BLAKE2b-256 checksum How to use checksums |
041938d5f8be87fef8c6a7233f2164957669afb39eae2590aabc4c03c2b3bb3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pymdict 0.0.4
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.