Skip to main content

An easy-to-use wrapper for psycopg2 for students.

Project description

pg-facile

An easy-to-use wrapper for psycopg2 for those who only care to type a SQL statement and get its result with column names in an easy to use format (namely: students).

Disclaimer

This package is used within a Web Services course where students do not have much time to learn and practice the proper way of accessing databases in Python: https://www.python.org/dev/peps/pep-0249/

Indeed, databases are not the core of the course; the architecture is what matters most and students are quickly encouraged to use ORM libraries such as SQLAlchemy over typing their own SQL statements.

Please refrain from using this package. It is merely a small wrapper around psycopg2 (link).

Getting Started

The following instructions illustrate how to use this package.

Prerequisites

Ideally you should have installed the virtualenv command and Python 3.

Also, you will need access to a postgresql database. You should know how to describe the host and credentials in URL form; such as postgres://[user[:password]@][netloc][:port][/dbname].

If you have Docker installed, then you may run docker run -p 5432:5432 -e POSTGRES_PASSWORD=123456 --rm -d postgres to start a local server whose URL will be: postgres://postgres:123456@localhost:5432/postgres.

Installing

Using pip:

pip install pg-facile

Ideally this should be preceded by the creation and activation of a virtual environment:

virtualenv -p python3 venv
source venv/bin/activate

Example

Here is an example using the pg-facile module:

from pg-facile import Database

url = 'postgres://postgres:123456@localhost:5432/postgres'

with Database(url) as db:
  db.execute('CREATE TABLE numbers (value INTEGER)')

  for i in range(50):
    db.execute('INSERT INTO numbers(value) VALUES (:val)', {'val': i})


with Database(url) as db:
  rows = db.executeAndFetchAll('SELECT * FROM numbers WHERE value % 2 = 0')
  for row in rows:
    print(row)

Contributing

No contributions are expected nor wanted. Yet, if you find a bug or which to enhance this humble package, you may:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

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

pg-facile-0.0.5.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

pg_facile-0.0.5-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pg-facile-0.0.5.tar.gz.

File metadata

  • Download URL: pg-facile-0.0.5.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

File hashes

Hashes for pg-facile-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6cf1b16acfda73ce6643e049d968d0ada23405bef438de0dd07b7e668557fc67
MD5 cff41596fdee72c957a7f4be55609416
BLAKE2b-256 98c9f0e8dc9ce9343852bf486ef78a3d80bbd5cc1a39c2108191ae58a017ae44

See more details on using hashes here.

File details

Details for the file pg_facile-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pg_facile-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

File hashes

Hashes for pg_facile-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ae4d880ab2167f16a82c75e24dc91b35877b0c90610f10bc8926518e34618d8d
MD5 e7af761efe9fb1cb243073a32fa98ce4
BLAKE2b-256 b2d3705438aac350a8d736f089628dc90910a2ed28775fd54b1394eabd047c06

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