For logging & accessing application data with NoSQL databases (MongoDB & ElasticSearch)
Project description
python-nosql-logger
Installation steps if using MongoDB
pip install pymongo #"pymongo[srv]" or "pymongo[aws]"
pip install python-nosql-logger
Initialize
For synchronous mongo logger
from pynosql_logger.loggers import MongoLogger
connection_string = 'your_mongodb_connection_string'
logger = MongoLogger(connection_string)
For asynchronous mongo logger
from pynosql_logger.async_loggers import AsyncMongoLogger
connection_string = 'your_mongodb_connection_string'
logger = AsyncMongoLogger(connection_string)
Installation steps if using ElasticSearch
pip install requests
pip install python-nosql-logger
Initialize
For synchronous elastic logger
from pynosql_logger.loggers import ElasticLogger
elastic_url = 'http://127.0.0.1:9200'
logger = ElasticLogger(elastic_url)
For asynchronous elastic logger
from pynosql_logger.async_loggers import AsyncElasticLogger
elastic_url = 'http://127.0.0.1:9200'
logger = AsyncElasticLogger(elastic_url)
Add Log
req_json = {
'users': {
'first_name': 'Hitesh',
'last_name': 'Mishra',
'email': 'hiteshmishra708@gmail.com'
}
}
resp = logger.add_log(req_json)
Add Bulk Log
req_json = {
'users': [{
'first_name': 'Test',
'last_name': 'User 1',
'email': 'testuser1@mailnesia.com'
}, {
'first_name': 'Test',
'last_name': 'User 2',
'email': 'testuser2@mailnesia.com'
}]
}
resp = logger.add_log(req_json)
Get Log
You can pass mongo query or elastic query to get the logs
req_json = {
'users': {
'first_name': 'Hitesh'
}
}
resp = logger.get_log(req_json)
Get All Logs
req_json = {
'collection': 'users'
}
resp = logger.get_all_logs(req_json)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for python_nosql_logger-1.0.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1dee6fe6de0c287f091927af59b2aaab7f9763e0c14e4481862ebc64fbc53e6 |
|
MD5 | 162ef7dd94fca4b1b3a685621e41eec8 |
|
BLAKE2b-256 | 18e56df0110e3dcbf9fdd533d38aa7315d8081c42e3466e3c813a5ec85169e2f |
Close
Hashes for python_nosql_logger-1.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29152b5f88c3bff2663658f8501d1246e1a1627702217e95042b78452c9e73b |
|
MD5 | 9c21d21eb91651ecf0bf401a54cd2ae2 |
|
BLAKE2b-256 | 959864f8c860403d58d6a1518f96ce160d7603f1ab2b68a46fd921b62b2d518f |