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.3a0.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.3a0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pypsql-0.0.3a0.tar.gz
Algorithm Hash digest
SHA256 4a9fbd1f5832659c51acd80aa55214b123b1971affdb2b80690c9695bdc54d4f
MD5 bf8a1f7cf14dd0d685e0ba0d7a87389e
BLAKE2b-256 ec50dc788d104c19925b0eab57dad249e2c0bcb9f4ae27201def1bd5067b9517

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pypsql-0.0.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bd41ce6864286a5e13b0e6683560e771c976e0df16e9741626a3d85dc6e9c08
MD5 f38f50a42eca90cf39a6f105bf863965
BLAKE2b-256 d120e837bc5ec5d1420a4bf8c8bfe3b41931b8ff2bb39a9ac01696568043de20

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