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.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9c6cee80bcedf5527ecd3419059e0c9823c411e897dcd00d69a8b13f30fc9ae |
|
MD5 | 5afa5210efa7d8d7594f8c641be2e1a3 |
|
BLAKE2b-256 | 493d4815780d1557b33bc676d74068e61425c2a76b8a3bf6341b82cd23899bad |
Close
Hashes for python_nosql_logger-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b17fb6ab3700387ab4d4fa4df6241f29b03fbf7860c39157324548cd197b779 |
|
MD5 | 5b1a8feabb9e52ba65c8265b94e6636f |
|
BLAKE2b-256 | 27370c7dfd52db819dde4c58e04cbdd23e4d93232f3f345e9fc7434b3e4b209c |