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

This version

1.7.3

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.3.tar.gz (29.4 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: database_common_tools-1.7.3.tar.gz
  • Upload date:
  • Size: 29.4 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.3.tar.gz
Algorithm Hash digest
SHA256 5367aa0b74580e003ad82897a404a0176ea1e24094ae412cdb27d2514f21402a
MD5 f5c1a5af8513f97a3bee446330f2efb9
BLAKE2b-256 976c23315d29ae644e29c8a55b172a1ab2451257e8579f9ac19dc8fc80c3ce20

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