tinymongo 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: tinymongo
3
+ Version: 1.0.0
4
+ Summary: A flat file drop in replacement for mongodb. Requires TinyDB
5
+ Author-email: Stephen Chapman <schapman1974@gmail.com>
6
+ License: The MIT License (MIT)
7
+
8
+ Copyright (c) 2016 Stephen Chapman
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ ~
16
+
17
+ Project-URL: Homepage, https://github.com/schapman1974/tinymongo
18
+ Project-URL: Source, https://github.com/schapman1974/tinymongo
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: License :: OSI Approved :: MIT License
22
+ Classifier: Topic :: Database
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE.txt
26
+ Requires-Dist: tinydb==3.2.1
27
+ Requires-Dist: tinydb-serialization==1.0.4
28
+ Requires-Dist: pymongo>=3.4.0
29
+ Requires-Dist: pyarrow>=10.0.0
30
+ Requires-Dist: portalocker>=2.7.0
31
+ Provides-Extra: uv
32
+ Requires-Dist: uvicorn>=0.23.0; extra == "uv"
33
+ Dynamic: license-file
34
+
35
+ [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/schapman1974/tinymongo)
36
+
37
+
38
+ ![logo](artwork/tinymongo.png)
39
+
40
+ [![Build Status](https://travis-ci.org/schapman1974/tinymongo.svg?branch=master)](https://travis-ci.org/schapman1974/tinymongo)
41
+
42
+ # Purpose
43
+
44
+ A simple wrapper to make a drop in replacement for mongodb out of
45
+ [tinydb](http://tinydb.readthedocs.io/en/latest/). This module is an
46
+ attempt to add an interface familiar to those currently using pymongo.
47
+
48
+ # Status
49
+
50
+ Unit testing is currently being worked on and functionality is being
51
+ added to the library. Current coverage is 93%. Current builds tested
52
+ on Python versions 2.7 and 3.3+.
53
+
54
+ # Installation
55
+
56
+ The latest stable release can be installed via `pip install tinymongo`.
57
+
58
+ The library is currently under rapid development and a more recent version
59
+ may be desired.
60
+
61
+ In this case, simply clone this repository, navigate
62
+ to the root project directory, and `pip install -e .`
63
+
64
+ or use `pip install -e git+https://github.com/schapman1974/tinymongo.git#egg=tinymongo`
65
+
66
+ This
67
+ is a pure python distribution and - thus - should require no external
68
+ compilers or tools besides those contained within Python itself.
69
+
70
+ # Notes for this fork
71
+
72
+ - **Default storage:** this fork uses Parquet v2 files by default (via `pyarrow`) for improved I/O performance and reliability. If `pyarrow` is not available, it falls back to TinyDB's default JSON storage.
73
+ - **Concurrency:** writes use atomic temp-file replace and optional advisory locks (`portalocker`) to reduce corruption risk under concurrent writers.
74
+ - **Tests & CI:** a GitHub Actions workflow is included at `.github/workflows/ci.yml` to run unit tests and linters across Python versions. See `requirements-dev.txt` for dev dependencies.
75
+
76
+
77
+ # Examples
78
+
79
+ The quick start is shown below. For a more detailed look at tinymongo,
80
+ take a look at demo.py within the repository.
81
+
82
+ ```python
83
+ from tinymongo import TinyMongoClient
84
+
85
+ # you can include a folder name or absolute path
86
+ # as a parameter if not it will default to "tinydb"
87
+ connection = TinyMongoClient()
88
+
89
+ # either creates a new database file or accesses an existing one named `my_tiny_database`
90
+ db = connection.my_tiny_database
91
+
92
+ # either creates a new collection or accesses an existing one named `users`
93
+ collection = db.users
94
+
95
+ # insert data adds a new record returns _id
96
+ record_id = collection.insert_one({"username": "admin", "password": "admin", "module":"somemodule"}).inserted_id
97
+ user_info = collection.find_one({"_id": record_id}) # returns the record inserted
98
+
99
+ # you can also use it directly
100
+ db.users.insert_one({"username": "admin"})
101
+
102
+ # returns a list of all users of 'module'
103
+ users = db.users.find({'module': 'module'})
104
+
105
+ #update data returns True if successful and False if unsuccessful
106
+ upd = db.users.update_one({"username": "admin"}, {"$set": {"module":"someothermodule"}})
107
+
108
+ # Sorting users by its username DESC
109
+ # omitting `filter` returns all records
110
+ db.users.find(sort=[('username', -1)])
111
+
112
+ # Pagination of the results
113
+ # Getting the first 20 records
114
+ db.users.find(sort=[('username', -1)], skip=0, limit=20)
115
+ # Getting next 20 records
116
+ db.users.find(sort=[('username', -1)], skip=20, limit=20)
117
+
118
+ # Getting the total of records
119
+ db.users.count()
120
+
121
+ ```
122
+
123
+ # Custom Storages and Serializers
124
+
125
+ > HINT: Learn more about TinyDB storages and Serializers in [documentation](https://tinydb.readthedocs.io/en/latest/usage.html#storages-middlewares)
126
+
127
+ ## Custom Storages
128
+
129
+ You have to subclass `TinyMongoClient` and provide custom storages like
130
+ CachingMiddleware or other available TinyDB Extension.
131
+
132
+ ### Caching Middleware
133
+
134
+ ```python
135
+ from tinymongo import TinyMongoClient
136
+ from tinydb.storages import JSONStorage
137
+ from tinydb.middlewares import CachingMiddleware
138
+
139
+ class CachedClient(TinyMongoClient):
140
+ """This client has cache"""
141
+ @property
142
+ def _storage(self):
143
+ return CachingMiddleware(JSONStorage)
144
+
145
+ connection = CachedClient('/path/to/folder')
146
+ ```
147
+
148
+ > HINT: You can nest middlewares: `FirstMiddleware(SecondMiddleware(JSONStorage))`
149
+
150
+
151
+ ## Serializers
152
+
153
+ To convert your data to a format that is writable to disk TinyDB uses the Python JSON module by default. It's great when only simple data types are involved but it cannot handle more complex data types like custom classes.
154
+
155
+ To support serialization of complex types you can write
156
+ your own serializers using the `tinydb-serialization` extension.
157
+
158
+ First you need to install it `pip install tinydb-serialization`
159
+
160
+ ## Handling datetime objects
161
+
162
+ You can create a serializer for the python `datetime` using
163
+ the following snippet:
164
+
165
+ ```python
166
+ from datetime import datetime
167
+ from tinydb_serialization import Serializer
168
+
169
+ class DatetimeSerializer(Serializer):
170
+ OBJ_CLASS = datetime
171
+
172
+ def __init__(self, format='%Y-%m-%dT%H:%M:%S', *args, **kwargs):
173
+ super(DatetimeSerializer, self).__init__(*args, **kwargs)
174
+ self._format = format
175
+
176
+ def encode(self, obj):
177
+ return obj.strftime(self._format)
178
+
179
+ def decode(self, s):
180
+ return datetime.strptime(s, self._format)
181
+ ```
182
+
183
+ > NOTE: this serializer is available in `tinymongo.serializers.DateTimeSerializer`
184
+
185
+
186
+ Now you have to subclass `TinyMongoClient` and provide customs storage.
187
+
188
+ ```python
189
+ from tinymongo import TinyMongoClient
190
+ from tinymongo.serializers import DateTimeSerializer
191
+ from tinydb_serialization import SerializationMiddleware
192
+
193
+
194
+ class CustomClient(TinyMongoClient):
195
+ @property
196
+ def _storage(self):
197
+ serialization = SerializationMiddleware()
198
+ serialization.register_serializer(DateTimeSerializer(), 'TinyDate')
199
+ # register other custom serializers
200
+ return serialization
201
+
202
+
203
+ connection = CustomClient('/path/to/folder')
204
+ ```
205
+
206
+ # Flask-Admin
207
+
208
+ This extension can work with Flask-Admin which gives a web based administrative
209
+ panel to your TinyDB. Flask-Admin has features like filtering, search, web forms to
210
+ perform CRUD (Create, Read, Update, Delete) of the TinyDB records.
211
+
212
+ You can find the example of Flask-Admin with TinyMongo in [Flask-Admin Examples Repository](https://github.com/flask-admin/flask-admin/tree/master/examples/tinymongo)
213
+
214
+ > NOTE: To use Flask-Admin you need to register a DateTimeSerialization as showed in the previous topic.
215
+
216
+ # Contributions
217
+
218
+ Contributions are welcome! Currently, the most valuable contributions
219
+ would be:
220
+
221
+ * adding test cases
222
+ * adding functionality consistent with pymongo
223
+ * documentation
224
+ * identifying bugs and issues
225
+
226
+ # Future Development
227
+
228
+ I will also be adding support for gridFS by storing the files somehow and indexing them in a db like mongo currently does
229
+
230
+ More to come......
231
+
232
+ # License
233
+
234
+ MIT License
@@ -0,0 +1,12 @@
1
+ tinymongo/__init__.py,sha256=3hfekaT5b_pqhMaKWooKzQB4xWE-OMdJAv8991lcVGk,107
2
+ tinymongo/errors.py,sha256=FQU1tKhM7ZGIzZ6KPv_tDUl1srzXploQkJ1S79crV2c,1664
3
+ tinymongo/parquet_storage.py,sha256=Bxn3_TPCpKmZFljaDrsggH9tbzJtfYB5fij546OxgR0,9044
4
+ tinymongo/results.py,sha256=HcMaO4HskP_0gXkvLcfPSmKdABT2_PFpWNTvzmo9xfg,3409
5
+ tinymongo/serializers.py,sha256=uDjIKvF1oBkhL2EDq6e8WbHSqOAYOuQ2gRQvP_ltf0w,646
6
+ tinymongo/storage_backends.py,sha256=PrCP9WzzBUhCVpbCiSxfywzcDSBghrA9MTpqYnyeXz0,4903
7
+ tinymongo/tinymongo.py,sha256=97Zu9MxUdsG1xG3jc-t2HYfwcJmjzRLorg_yUP60qDY,34132
8
+ tinymongo-1.0.0.dist-info/licenses/LICENSE.txt,sha256=YPo2oONk31kuLbBq2CaSQsCCkXAxq4KRutYN2vv3KP0,1084
9
+ tinymongo-1.0.0.dist-info/METADATA,sha256=ulUg4dHqigzWBIf25GqFBJqUCF1KPIkSWIRo65H3BO8,8880
10
+ tinymongo-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
11
+ tinymongo-1.0.0.dist-info/top_level.txt,sha256=OeWR-1XMYO15aoVd9cgcYrUbsSuE-6MfokUHbtbgbp4,10
12
+ tinymongo-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Stephen Chapman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+ ~
@@ -0,0 +1 @@
1
+ tinymongo