Metadata-Version: 2.4
Name: pgbenchmark
Version: 0.0.3
Summary: A Python package to benchmark query performance and comparison on PostgreSQL Database
Author-email: Elguja Lomsadze <lomsadze.guja@gmail.com>
License: Apache License 2.0
Project-URL: Homepage, https://github.com/GujaLomsadze/pgbenchmark
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: psycopg2-binary>=2.9.10
Requires-Dist: SQLAlchemy>=2.0.40
Requires-Dist: click>=8.1.3
Requires-Dist: fastapi>=0.115.12
Requires-Dist: uvicorn>=0.34.0
Dynamic: license-file

# pgbenchmark

`pgbenchmark` is a Python package to benchmark query performance on a PostgreSQL database. It allows you to measure the
execution time of queries over multiple runs, providing detailed metrics about each run's performance.

## [--- UNDER DEVELOPMENT ---]

## Getting Started

```shell
pip install pgbenchmark
```

---

```python
import psycopg2
from pgbenchmark import Benchmark

# Connect to PostgreSQL
conn = psycopg2.connect(
    dbname="",
    user="",
    password="",
    host="",
    port=""
)

# Create benchmark instance with desired number of Runs
num_runs = 100_000

# Create a Benchmark class
benchmark = Benchmark(db_connection=conn, number_of_runs=num_runs)

# Set .SQL file to fetch the query from for Benchmark
benchmark.set_sql("./test.sql")

# Or directly pass Raw SQL query
# benchmark.set_sql("SELECT 1;")

# Run the benchmark
benchmark.execute_benchmark()

# Get execution time summary
print("Execution Summary:", benchmark.get_execution_results())

# -----------------------------------------------

# Get execution timeseries using the generator
# (Useful if you want to visualize it as a table.
# "sent_at" is timestamp where `cursor.execute()` was initiated

for execute_data in benchmark.get_execution_timeseries():
    print(execute_data['sent_at'], execute_data['duration'])

```
