A fast python API for storing and querying time series in MongoDb.
- Free software: MIT license
- Documentation: https://mongots.readthedocs.io.
- python >= 3.3
- MongoDb >= 3.4
Install package:
pip install mongots
Manual install:
- Clone this repo:
git clone [email protected]:AntoineToubhans/MongoTs.git
- install dependencies:
pip install -r requirements.txt
You can instanciate client, database, collection just like you would do with pymongo:
import mongots client = mongots.MongoTSClient() db = client.MyDatabase collection = db.temperatures
collection.insert_one(value, datetime, tags=tags)
Arguments:
value
(float): the value to be insertedtimestamp
(ddatemie.datetime): the timestamp for the valuetags
(dict, default=None): tags for the value; can be use the search/filter the value later on.
Return (bool): True
if the insertion succeeded, False
otherwise.
collection.query(start, end, tags=tags, aggregateby=aggregateby, groupby=groupby)
Arguments:
start
(datetime): filters values after the start datetimeend
(datetime): filters values before the end datetimeaggregateby
(str): aggregates value per interval:- years: '1y', '2y', ...
- month '1M', '2M', ...
- days: '1d', '2d', ...
- hours: '1h', '2h', ...
tags
(dict, default=None): similar to a mongo filtergroupby
(array): return statistics grouped by a list of tags (string)
Return (pandas.DataFrame): dataframe containing the statistics and indexed by datetimes.
collection.get_tags()
Return (dict): The tags contained in the collection.
collection.get_timerange():
- Return (None | tuple):
- None if the collection is empty. Otherwise, a tuple containing two datetime object representing the minimum and maximum timestamps in the collection.
Integration test requires a MongoDb to be up (run docker-compose up).
Launch all tests:
pytest
Launch only unit test:
python -m unittest -v test