Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

A Python package to create simple SQL queries from the console, and quickly display the returned information.

Project description

Helper to consume a database from the REPL.

Dependencies:

  • pypyodbc
  • tabulate
  • Configuration file dbhelper.ini. A template is included in the source.

Full documentation available in https://github.com/sebasmonia/pyquebec/wiki

Sample:

>>> from pyquebec import database
>>> from pyquebec import dataformatters as qf
>>> master = database.connect('master')  # Connection string name from the ini file, or an entire conn string
>>> master.dbo.sp <TAB KEY>
db.dbo.spt_fallback_db  db.dbo.spt_fallback_usg db.dbo.spt_values
db.dbo.spt_fallback_dev db.dbo.spt_monitor
>>>result = db.dbo.spt_monitor.From().go()
>>> qf.to_html(result)
Creating and opening temp file C:\Users\smonia\AppData\Local\Temp\tmpn3g43ppp.htm
>>> qf.to_csv(result)
Creating and opening temp file C:\Users\smonia\AppData\Local\Temp\tmpe68shxd9.csv
>>> result[0]
row(lastrun=datetime.datetime(2015, 5, 13, 23, 34, 58, 77000), cpu_busy=59, io_busy=29,
idle=288, pack_received=0, pack_sent=0, connections=12, pack_errors=0, total_read=0, total_write=0, total_errors=0)

Pypyodbc returns tuples by default. This library converts them to namedtuples for increased readability and to make it easier to keep playing with the data using filter, map, sorted, etc.

The formatters work with iterables using lists, tuples, dictionaries and namedtuples as rows. There’s a third option that uses tabulate for output to_console(). Both HTML and CSV options create a temp file and use os.startfile (in Windows you get the default browser and, usually, Excel).

Roadmap (help/guidance appreciated!):

  • Other alternatives in PyPI didn’t support SQL Server. This one was tested using SQL Server, but should work with other RDBMS with minimal effort. The final aim is to support as many as possible (all?)
  • The API for querying might need a few tweaks. Suggestions are welcome.
  • Decide on other SQL features to support beyond basic querying. UPDATES, INSERTS, GROUP BY, etc, would it make sense? Would this make supporting other products more difficult?
  • Needs unittest!

Contributors: Sebastián Monía - http://github.com/sebasmonia Fernando Antivero - http://github.com/ferantivero

Project details


Release history Release notifications

History Node

0.9.0

This version
History Node

0.5.1

History Node

0.5.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pyquebec-0.5.1-py3-none-any.whl (74.9 kB) Copy SHA256 hash SHA256 Wheel 3.4 Oct 28, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page