Skip to main content

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.txt for 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

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

database_common_tools-1.7.6.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

database_common_tools-1.7.6-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file database_common_tools-1.7.6.tar.gz.

File metadata

  • Download URL: database_common_tools-1.7.6.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for database_common_tools-1.7.6.tar.gz
Algorithm Hash digest
SHA256 05f571588ab635cf8eddf39dffcbe7cad12f36591cdf265ad02c373b618f43e7
MD5 43610487e19f4e83d32db9b1b8966c6b
BLAKE2b-256 cf442eec8221119ab8702123f4a167beae935a7059cc95be8ee71e7c0e6b0abe

See more details on using hashes here.

File details

Details for the file database_common_tools-1.7.6-py3-none-any.whl.

File metadata

File hashes

Hashes for database_common_tools-1.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ce7ac1c3e2a1de51231a17fb9d177131404520cb028f0bc1773af18784790493
MD5 f4890fe3aff2d53cd916f514e8991561
BLAKE2b-256 09d5ce32cc2d52f1bc7916d889be7d3acfff01e8be74adb56e10dd60d858713a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page