Skip to main content

Functionality to connect and interact with PostgreSQL servers

Project description

pypSQL

pypsql utilities website

License: MIT

pypsql is a lightweight framework for connecting to PostgreSQL databases, whether locally or remotely hosted. It builds on top of SQLAlchemy to provide a simple, Pythonic interface for establishing connections, running queries, and managing database sessions.

Contributors

Marius Liebald (maintainer)

Installation

pip install pypsql

Basic Usage

Provide database credentials

You can store the database connection details in a file, for example:

SERVER=<host name or address>   # e.g., localhost, 127.0.0.1, or a public IP
PORT=<port number>              # default: 5432
NAME_DATABASE=<database name>   # e.g., my_db
NAME_USER=<role>                # e.g., Alice
PASSWORD_USER=<password>        # e.g., 123abc

You may place this file anywhere on the client machine. Importantly, this step is optional. You can also provide the variables interactively via terminal prompts.

No SSH required

An SSH tunnel is not needed if:

  • the server and client run on the same machine,
  • the server and client are in the same (virtual) network, or
  • the server is accessible via its public IP.

In this case, simply run the Python script:

import pypsql
from pathlib import Path

conn = pypsql.DatabaseConnector(
    path=Path(<path to the credential file>), # e.g., "/Users/marius/Desktop/" # if the .env file is located in the same directory as the script you are executing, you can leave this argument undefined
    db_credential_file=<name of credential file>   # e.g., ".env" (default) or "credentials.py"
)

sql_script = """
SELECT *
FROM customers
"""

df = conn.get_data(sql_script)

print(df)

Note that this example assumes the database contains a table named customers.

Connection via SSH

To be filled.

Official Documentation

The documentation is hosted under https://www.marius-liebald.com/pypsql/index.html

License

The package is distributed under the MIT license.

References

Bayer, Michael, and contributors. 2025. “SQLAlchemy.” https://www.sqlalchemy.org/.

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

pypsql-0.0.4a0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

pypsql-0.0.4a0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pypsql-0.0.4a0.tar.gz.

File metadata

  • Download URL: pypsql-0.0.4a0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for pypsql-0.0.4a0.tar.gz
Algorithm Hash digest
SHA256 39b7e80c30d84948672301ec8691442f02c9d6f3c755644fe994f15d78245e71
MD5 560f0ce529ac6caf80294c17e87dad21
BLAKE2b-256 4ad432e038acb4dedd91a19bd73d51965f34d90f5f87e09f23ee97679c7db3b2

See more details on using hashes here.

File details

Details for the file pypsql-0.0.4a0-py3-none-any.whl.

File metadata

  • Download URL: pypsql-0.0.4a0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for pypsql-0.0.4a0-py3-none-any.whl
Algorithm Hash digest
SHA256 1947a7fbbacd19657aaf8a2265c1b5471569721d01250c2460ce7dafdce62d67
MD5 a901e6f688810d8b265735826c1d4c95
BLAKE2b-256 393b23959bc86e740e48b05f9dbeb47fa5aba1d69e0dcca87425889cee9d5833

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