let message middleware and use database more easy
Project description
Database Common Tools
A Python library that makes it easier to work with message middleware and databases. This library provides convenient utilities for connecting to and working with Redis, MongoDB, MySQL, Kafka, and OpenSearch.
Features
- Redis: Easy connection and data manipulation utilities
- MongoDB: Simplified connection and query operations
- MySQL: Database connection and query helpers
- Kafka: Consumer utilities for message processing
- OpenSearch/Elasticsearch: Search and indexing utilities
- JSON Analysis: Tools for parsing and analyzing JSON documents
- Data Analysis: Field analysis and data processing utilities
Installation
pip install database-common-tools
Or install from source:
git clone https://github.com/yangming9/database-common-tools.git
cd database-common-tools
pip install -e .
Requirements
- Python >= 3.6
- See
requirements.txtfor full dependency list
Quick Start
Redis
from databasetools import rd_connect, rd_set, rd_get
# Connect to Redis
rd = rd_connect(host='localhost', port=6379, password='')
# Set and get values
rd_set(rd, 'key', 'value')
value = rd_get(rd, 'key', log)
MongoDB
from databasetools import mongo_conn, mongo_find_all
# Connect to MongoDB
mongo = mongo_conn(host='localhost', port=27017, database='mydb', log=log)
# Query documents
docs = mongo_find_all(mongo, 'collection_name')
MySQL
from databasetools.mysql_connect_v2 import MySQLConnector
# Create connector
connector = MySQLConnector(
host='localhost',
port=3306,
user='root',
password='password',
database='mydb',
log=log
)
# Connect and query
connector.connect()
results = connector.execute_query("SELECT * FROM users")
connector.disconnect()
Kafka
from databasetools import kafka_consumer
# Consume messages
for message in kafka_consumer(bootstrap_servers=['localhost:9092'], topic='my_topic'):
print(message.value)
Project Structure
database-common-tools/
├── databasetools/ # Main package
│ ├── __init__.py # Package initialization and exports
│ ├── redis_connect.py # Redis utilities
│ ├── mongo_connect.py # MongoDB utilities
│ ├── mysql_connect.py # MySQL utilities
│ ├── kafka_connect.py # Kafka utilities
│ ├── opensearch_connect.py # OpenSearch utilities
│ ├── analysis_json.py # JSON analysis tools
│ └── ... # Other utilities
├── examples/ # Example files
├── test/ # Test files
├── setup.py # Package setup
├── pyproject.toml # Modern Python project configuration
├── requirements.txt # Runtime dependencies
├── requirements-dev.txt # Development dependencies
└── README.md # This file
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/yangming9/database-common-tools.git
cd database-common-tools
# Install in development mode
pip install -e .
# Install development dependencies
pip install -r requirements-dev.txt
Running Tests
pytest
Code Formatting
black databasetools/
Linting
flake8 databasetools/
Version History
See the releases page for version history.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Coder Yang
- Email: yma91412@gmail.com
- GitHub: @yangming9
Support
If you encounter any issues or have questions, please open an issue on GitHub.
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
File details
Details for the file database_common_tools-1.7.0.tar.gz.
File metadata
- Download URL: database_common_tools-1.7.0.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb0c6cdb26994bf66c43637eea1cb18da318d2503e10b9b2f05c5963ff0ce58c
|
|
| MD5 |
43bd1e1258de43441b9e397b2dec6ab7
|
|
| BLAKE2b-256 |
9b2bef87636c8e292671b45fa2b5152ce7656688768007918ba85ac1ec665c63
|