Skip to main content

A package for connecting to various databases (PostgreSQL, MySQL, SQL Server).

Project description

Cosmic Nexus 🚀

Cosmic Nexus is a Python package under the cosmiclode monorepo designed to provide robust and efficient database connectivity. It simplifies working with PostgreSQL, MySQL, and SQL Server by offering a unified interface with context management, error handling, and Pandas integration.


✨ Features

  • Database Abstraction: Consistent interface across supported databases.
  • Connection Management: Automatic connection handling and pooling (if supported).
  • Factory Pattern: Easily create connectors using DBConnectorFactory.
  • Context Management: Ensures clean resource management with with blocks.
  • Error Handling: Custom exceptions for clear debugging.
  • Pandas Integration: Query results are returned as DataFrames.

📦 Installation

pip install cosmiclode.cosmic-nexus

To install database-specific extras:

pip install "cosmiclode.cosmic-nexus[postgresql]"
pip install "cosmiclode.cosmic-nexus[mysql]"
pip install "cosmiclode.cosmic-nexus[sqlserver]"

🚀 Quick Start

from cosmiclode.cosmic_nexus import DBConnectorFactory
from cosmiclode.cosmic_nexus.exceptions import ConnectionError, QueryError

config = {
    "type": "postgresql",
    "host": "localhost",
    "database": "my_db",
    "user": "user",
    "password": "pass",
    "port": 5432
}

try:
    connector = DBConnectorFactory.create_connector(config)
    with connector as db:
        df = db.execute_query("SELECT * FROM my_table;")
        print(df)
except (ConnectionError, QueryError) as e:
    print(f"Error: {e}")

📚 Usage Notes

  • Use %s placeholders for parameters to avoid SQL injection.
  • SQL Server requires a full ODBC connection string in the config.
sqlserver_config = {
    "type": "sqlserver",
    "connection_string": "DRIVER={ODBC Driver 17 for SQL Server};SERVER=...;UID=...;PWD=..."
}

📝 License

This project is licensed under the MIT License.


✨ Author

Vinod Yerrapureddy
📧 yerrapureddyvinodreddy@gmail.com
🌐 vinodreddy.netlify.app
🔗 LinkedIn
🍥 Anime fan | 💻 Data engineer | 🛠️ Systems hacker

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmiclode_cosmic_nexus-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

cosmiclode_cosmic_nexus-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file cosmiclode_cosmic_nexus-0.1.0.tar.gz.

File metadata

  • Download URL: cosmiclode_cosmic_nexus-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for cosmiclode_cosmic_nexus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 27d486d13fa8cc27dbfb92229d69e63da87916873efaa122c88a191f5f91b65c
MD5 20945dce9b20e7eebe78f5337c79efff
BLAKE2b-256 439d54f50b0eacaa4d4385508b5e3128c50c7e8d990d33144291609a7f1f14a5

See more details on using hashes here.

File details

Details for the file cosmiclode_cosmic_nexus-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cosmiclode_cosmic_nexus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cac2dfd3b6231264cdcc1a90652e05a7ee20cd5049a041aa26984f6c3853c9e
MD5 9b1cccf1045aca9bf8169ac03e8b54ed
BLAKE2b-256 da818f543369a4b6748bc75a648de05a59b956b838515d04489ec48b29333292

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