API reference¶
This page is generated from the source docstrings with mkdocstrings. It documents the most useful public entry points; browse the source for the full surface.
Configuration¶
pgcarter.config ¶
Runtime configuration for pgcarter.
Config
dataclass
¶
Resolved configuration derived from CLI arguments and defaults.
Source code in pgcarter/config.py
resolve_config ¶
resolve_config(*, host: str, port: int, database: str, user: str, password: str | None, output_dir: str | None, templates_dir: str | None, schemas: list[str] | None = None, log_level: str = 'INFO') -> Config
Apply documented defaults and return a :class:Config.
Per spec
output_dirdefaults to the database name.templates_dirdefaults to./templates.- password may also be supplied via the
PGPASSWORDenvironment variable.
Source code in pgcarter/config.py
Metadata models¶
The dataclasses below are the single source of truth shared by the SQL generation, JSON, and documentation layers.
pgcarter.models ¶
Metadata models for extracted PostgreSQL assets.
These dataclasses are the single source of truth that both the SQL generation layer and the documentation (Jinja2) rendering layer consume. They are plain dataclasses (no behaviour beyond serialisation) so they are trivially serialisable to JSON and passed verbatim into templates.
Grant
dataclass
¶
Bases: _Serialisable
A single privilege grant on an object.
Source code in pgcarter/models/__init__.py
Relationship
dataclass
¶
Bases: _Serialisable
An edge in the object dependency / relationship graph.
Source code in pgcarter/models/__init__.py
Inventory
dataclass
¶
Bases: _Serialisable
Aggregate of everything extracted from a single database.
Source code in pgcarter/models/__init__.py
Run report¶
pgcarter.report ¶
Run report collection: extracted/skipped objects, warnings, and errors.
Report
dataclass
¶
Accumulates the outcome of an extraction + generation run.
Source code in pgcarter/report.py
Logging¶
pgcarter.logging_config ¶
Structured logging configuration for pgcarter, built on structlog.
Production default: line-delimited JSON to stdout, ready for ingestion by log
aggregators (Datadog, ELK/OpenSearch, CloudWatch, Loki, …). Enable colourised
developer console output with pretty_logs=True or LOG_PRETTY=true.
Both stdlib logging.getLogger and structlog.get_logger are supported and
render through the same pipeline, so existing %-style calls keep working
while new code can emit structured key/value events. Context bound via
structlog.contextvars.bind_contextvars (e.g. request_id) is automatically
attached to every event.
configure_logging ¶
Configure structlog and stdlib logging for the whole application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretty_logs
|
bool | None
|
|
None
|
level
|
str | None
|
Logging level name ( |
None
|
Logs are written to stdout. Calling this more than once reconfigures cleanly (the root handler is replaced).
Source code in pgcarter/logging_config.py
get_logger ¶
Return a structlog logger (stdlib-compatible).
Accepts %-style positional args and .exception() like the stdlib
logger it replaces, while also accepting structured keyword fields.
Source code in pgcarter/logging_config.py
Analysis engine¶
pgcarter.analyzer.config ¶
Analysis configuration: enabled checks, thresholds, and sampling.
Loaded from a YAML file (--config analysis.yml) shaped as::
analysis:
enabled_checks:
- null_analysis
- cardinality
- table_size
thresholds:
high_null_percentage: 80
low_cardinality_limit: 10
Every field has a documented default, so a partial (or absent) config is valid.
When enabled_checks is omitted, all registered checks run.
Thresholds
dataclass
¶
Numeric limits that turn a measurement into a warning.
Source code in pgcarter/analyzer/config.py
AnalysisConfig
dataclass
¶
Resolved analysis configuration.
Source code in pgcarter/analyzer/config.py
is_enabled ¶
load_analysis_config ¶
Load an :class:AnalysisConfig from YAML, applying defaults.
A missing path yields the default configuration. A CLI sample_size
overrides any value present in the file.
Source code in pgcarter/analyzer/config.py
pgcarter.analyzer.engine ¶
The analysis engine: run enabled checks and assemble the report.
The engine feeds each asset to the checks whose scope matches it (tables to
table checks, (table, column) pairs to column checks, the whole inventory to
database checks), then merges results into :class:TableAnalysis /
:class:ColumnAnalysis objects. Every non-informational result also becomes a
:class:Warning. A failure in one check is captured and never aborts the run,
mirroring the extractor's resilience model.
AnalysisEngine ¶
Run all enabled checks against an inventory (optionally a live DB).
Source code in pgcarter/analyzer/engine.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |