Skip to main content

Terminal output formatter and query executor for PyMySQL

Project description

pymysql-terminal

Lightweight wrapper around PyMySQL for executing queries and displaying results in the terminal.

Install

pip install pymysql-term

Or from source:

pip install git+https://github.com/amirullahmutalibov/pymysql-terminal.git

Usage

from pymysql_terminal import Connection, Executor

conn = Connection(host="localhost", database="mydb", user="root", password="root")
ex = Executor(conn)

# print query result as a table
ex.print_table("SELECT * FROM products WHERE discount > %s", (10,))

# fetch as list of dicts
rows = ex.fetch("SELECT * FROM orders")

# insert / update / delete
ex.execute("UPDATE products SET price = %s WHERE product_id = %s", (999.0, 1))

conn.close()

Output example

+------------+--------------+----------+----------+
| product_id | product_name | price    | discount |
+------------+--------------+----------+----------+
| 1          | Nike Zoom    | 1000.00  | 14.0     |
| 2          | Amir Imba    | 984000   | 18.0     |
+------------+--------------+----------+----------+
строк: 2

API

Connection(host, database, user, password, port, charset)

Connects to MySQL. Supports auto-reconnect.

Executor(connection)

  • fetch(sql, params)list[dict]
  • fetch_one(sql, params)dict
  • execute(sql, params) — INSERT / UPDATE / DELETE
  • print_table(sql, params) — prints formatted table to terminal

Formatter

  • print_table(rows) — print list of dicts as ASCII table
  • to_csv(rows, delimiter)str

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

pymysql_term-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

pymysql_term-1.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pymysql_term-1.0.0.tar.gz.

File metadata

  • Download URL: pymysql_term-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pymysql_term-1.0.0.tar.gz
Algorithm Hash digest
SHA256 25fdd9766b7c803e3009dc0bbe05f7218d20dd906864fded8b6cb82b2445c014
MD5 f229bac6344ae7f8d74e082e36b1b5b5
BLAKE2b-256 378b22ebb927cefe96ffb02daff01891bffa08c1500680fe6f35d579b47f2387

See more details on using hashes here.

File details

Details for the file pymysql_term-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pymysql_term-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pymysql_term-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4bbbab1c9657742573bb93ec16f7498aa9960fdad703c13b498697927c1d185
MD5 1d82bc4f41542164f965311bc661665a
BLAKE2b-256 10068adfd3034389ef22f6b4dd8643446619e2a9e674fcca11bf8d9983b0d008

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