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-1.0.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

pypsql-1.0.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file pypsql-1.0.1.tar.gz.

File metadata

  • Download URL: pypsql-1.0.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for pypsql-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5108bddd1f537720412498edb863631be24b3b8f0ef18c2d132f24363c60037c
MD5 246d181241f57925fb1fa8783052e8c6
BLAKE2b-256 2c56e893d0c74125af5a5f6297fd24a604cec465c59c68518e8314bf877c8826

See more details on using hashes here.

File details

Details for the file pypsql-1.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pypsql-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1d3e38164bd79ff50454fe321938adf0c90b7aecff1bf267df8f25f10298370
MD5 87c5b6630691ed997a7f9bfc3951a094
BLAKE2b-256 9af0304d155319ec209ad89f0e2b046a54d31c81709f44540ff26ad27ae0b372

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