PgSummary
All of pg_summary's functionality can be accessed by the PgSummary object, which includes all the methods and attributes mentioned in the sections below.
pg_summary.PgSummary
PgSummary(host: str, database: str, user: str, table_or_view: str, passwd: None | str = None, port: int = 5432, schema: str = 'public', outfile: Path | None = None, include_src: bool = False)
Create a summary of unique values for each column in a Postgres table or view and summarize results in an Excel workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host |
str
|
Name of the Postgres host. |
required |
database |
str
|
Name of the Postgres database. |
required |
user |
str
|
Name of the Postgres user. |
required |
table_or_view |
str
|
Name of the Postgres table or view to summarize. |
required |
passwd |
str
|
Password for the Postgres user. If not defined, the user will be prompted for the password. Defaults to None. |
None
|
port |
int
|
Port number of the Postgres host. Defaults to 5432. |
5432
|
schema |
str
|
Name of the Postgres schema containing the table or view to summarize. Defaults to "public". |
'public'
|
outfile |
Path
|
Path to the output Excel file containing summarized results. If not defined, the output file will be named |
None
|
include_src |
bool
|
Include the source table or view in the output Excel file as a separate sheet. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the schema does not exist. |
ValueError
|
If the table or view does not exist. |
ValueError
|
If the table or view has no rows. |
Examples:
>>> from pg_summary import PgSummary
...
... PgSummary(
... host="localhost",
... database="mydb",
... user="username",
... table_or_view="mytable",
... schema="public",
... include_src=True,
... ).summary()
Source code in pg_summary/pg_summary.py
get_column_names
Return a list of column names in a table or view.
Source code in pg_summary/pg_summary.py
get_column_dtype
Return the data type of a column.
Source code in pg_summary/pg_summary.py
get_unique_column_values
Return a list of unique values for a column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column |
str
|
Name of the column to query for unique values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
A tuple containing a list of unique values and the number of unique values. |
Source code in pg_summary/pg_summary.py
get_null_column_value_count
Return the number of null values for a column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column |
str
|
Name of the column to query for null values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of null values for the column. |
Source code in pg_summary/pg_summary.py
get_table_row_count
Return the number of rows in a table.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of rows in the table. |
Source code in pg_summary/pg_summary.py
summary
Create a summary of unique values for each column in a Postgres table or view and summarize results in an Excel workbook.
Source code in pg_summary/pg_summary.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |