CLI¶
Command-line interface for Koality.
This module provides the CLI for running, validating, and inspecting Koality data quality check configurations.
Example
Commands
- run: Execute data quality checks from a configuration file.
- validate: Validate a configuration file without executing checks (--connect: check tables and columns).
- explain: Show the resolved checks, their filters and thresholds, and the SQL a run executes.
- setup: Install the DuckDB extensions a configuration declares, without executing checks.
- print: Print the resolved configuration in various formats.
RunError ¶
Bases: ClickException
A configuration, connection or execution error of a koality command; exits with 2.
cli ¶
Koality - Data quality monitoring CLI.
Koality provides commands to run, validate, and inspect data quality check configurations. Use --help on any command for more details.
explain ¶
explain(config_path: Path, overwrites: tuple[str, ...], database_setup_variable: tuple[str, ...], bundles: tuple[str, ...], check_types: tuple[str, ...], output_format: str, connect_database: bool) -> None
Show what koality run would do, without reading data.
For each check: its bundle, type and name, the tables it reads, its thresholds, its filters after defaults and overwrites (-o), the query that checks its data exists, and the query that computes its result. With a database_accessor, a run first fetches each source table's rows into an in-memory staging catalog, once for all checks, and the checks read them there; those fetch queries follow the checks.
Without --connect, no database is contacted, and the SQL is written for DuckDB; a source with its own
backend (e.g. BigQuery) gets its own SQL in a run. With --connect, database_setup runs (as for koality run),
the SQL is written by the attached database's backend, and each fetch query (or, without a database_accessor,
each check's query) gets DuckDB's plan where DuckDB reads the source itself (not for e.g. BigQuery, which would
receive the query).
Exit codes:
0: The configuration was explained.
2: The configuration is invalid, a variable is undefined, a bundle doesn't exist, or (with --connect)
database_setup fails or a query can't be planned (the explanation is still printed, with the error).
130: Interrupted.
Usage examples:
koality explain --config_path checks.yaml
koality explain --config_path checks.yaml --bundle orders --check-type NullRatioCheck
koality explain --config_path checks.yaml -o partition_date=2023-01-01 --format json
koality explain --config_path checks.yaml --connect -dsv PROJECT_ID=my-gcp-project
Source code in src/koality/cli.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 | |
print_config ¶
print_config(config_path: Path, output_format: str, indent: int, overwrites: tuple[str, ...], database_setup_variable: tuple[str, ...], show_secrets: bool) -> None
Print the resolved koality configuration.
Displays the fully resolved configuration after default propagation. This shows the effective configuration that would be used during execution. Filter values can be overridden using --overwrites (-o) options. Overwrites are applied to defaults before validation, so they propagate to all checks automatically.
Database setup variables can be provided using --database_setup_variable (-dsv) or the DATABASE_SETUP_VARIABLES environment variable (comma-separated VAR=value pairs). They must all be defined, but database_setup is printed as written, with its ${VAR_NAME} placeholders, unless --show-secrets is given.
Output formats:
model: Pydantic model representation (Python repr).
yaml: YAML formatted output (default).
json: JSON formatted output.
Exit codes:
0: The configuration was printed.
2: The configuration is invalid or can't be read, or a variable is undefined.
Usage examples:
koality print --config_path checks.yaml
koality print --config_path checks.yaml --format json
koality print --config_path checks.yaml --format yaml --indent 4
koality print --config_path checks.yaml -o partition_date=2023-01-01
koality print --config_path checks.yaml -dsv PROJECT_ID=my-gcp-project --show-secrets
DATABASE_SETUP_VARIABLES="PROJECT_ID=my-project" koality print --config_path checks.yaml
Source code in src/koality/cli.py
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | |
run ¶
run(config_path: Path, overwrites: tuple[str, ...], database_setup_variable: tuple[str, ...], verbose: bool | None, exit_zero: bool) -> None
Run koality checks from a configuration file.
Executes all data quality checks defined in the configuration file. Filter values can be overridden using --overwrites (-o) options. Overwrites are applied to defaults before validation, so they propagate to all checks automatically.
Database setup variables can be provided using --database_setup_variable (-dsv) to substitute ${VAR_NAME} placeholders in the database_setup SQL. Variables can also be set via the DATABASE_SETUP_VARIABLES environment variable using comma-separated VAR=value pairs.
Usage examples:
koality run --config_path checks.yaml
koality run --config_path checks.yaml -o partition_date=2023-01-01
koality run --config_path checks.yaml -dsv PROJECT_ID=my-gcp-project
koality run --config_path checks.yaml -dsv PROJECT_ID=prod -dsv DATASET=analytics
DATABASE_SETUP_VARIABLES="PROJECT_ID=my-project,DATASET=prod" koality run --config_path checks.yaml
Exit codes:
0: All checks passed (monitor-only checks don't fail because of their thresholds).
1: At least one check failed, or its data is missing.
2: At least one check errored, the configuration or database setup is invalid, or a table is missing.
130: The run was interrupted.
Source code in src/koality/cli.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
setup ¶
Install the DuckDB extensions a configuration declares, without running checks.
Installs each extension in extensions that isn't installed yet into extension_directory (DuckDB's
default if not set), and loads it to check that it works with this DuckDB version. Run it while building
a Docker image or in a cached CI step: koality run then loads the extensions without network access.
Exit codes:
0: All extensions are installed and load.
2: The configuration is invalid, or an extension could not be installed or loaded.
Usage examples:
koality setup --config_path checks.yaml
koality setup --config_path checks.yaml --force
Source code in src/koality/cli.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
validate ¶
validate(config_path: Path, overwrites: tuple[str, ...], database_setup_variable: tuple[str, ...], connect_database: bool) -> None
Validate a koality configuration file without executing checks.
The configuration is loaded as koality run loads it: overwrites (-o) are applied before validation, and
every ${VAR_NAME} in database_setup must be defined through -dsv or the DATABASE_SETUP_VARIABLES
environment variable.
With --connect, database_setup runs (as for koality run, including extensions), and each table the
checks read is looked up in the database, with each check, filter, join and date column. All missing tables
and columns are reported at once, naming the bundle, the check (its index in the bundle) and the column.
No data is read.
Exit codes:
0: Configuration is valid (and, with --connect, its tables and columns exist).
2: Configuration is invalid, a variable is undefined, or (with --connect) database_setup fails or a table
or column is missing.
130: Validation was interrupted.
Usage examples:
koality validate --config_path checks.yaml
koality validate --config_path checks.yaml -o partition_date=2023-01-01
koality validate --config_path checks.yaml --connect -dsv PROJECT_ID=my-gcp-project
Source code in src/koality/cli.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |