Python API
Find public builder, client and configuration methods with signatures from the source.
Import the public entry points from metricraft. Use QueryBuilder for immutable
construction and DatabaseClient for I/O. All configurations live in the same
package.
Python type hints
MetriCraft 0.3.0 includes inline type hints and a py.typed marker for type
checkers and editors.
Fluent calls, Python operators and dialect-marked methods return QueryBuilder;
build() returns str. Client calls return MetricsQueryResult or the matching
metadata result, including when awaited. The installed-wheel CI checks these
contracts and ensures invalid argument types are rejected by mypy and Pyright.
Signatures use a few shared input aliases:
| Type | Accepted Python values |
|---|---|
Number | int or float (runtime checks reject booleans) |
ScalarInput | A number or QueryBuilder expression |
StringInput | A string or a string-valued expression |
QueryInput | A number, string or QueryBuilder expression |
Window | A duration string or duration expression |
BuildMode | QueryMode or the literal "promql" / "metricsql" |
MatchInput | A selector string, QueryBuilder, or a sequence (such as a list or tuple) containing either |
Python annotations check argument shapes and preserve chained return types. Rust
still validates expression kinds, allowed values, dialects and feature flags.
For example, a QueryBuilder used as a scalar argument must represent a scalar
in the selected language. HTTP adapter inputs use read-only mappings; decoded response values have type
object and need narrowing before use. See transport contracts.
Other dynamic data, such as diagnostics, can still contain Any values.
Reading the reference
The reference is divided into category pages. Signatures, parameter names, defaults and declaration links come from the Python source; each method also has an editorial purpose, parameter types, accepted values and return contract. The documentation build fails if a new method or parameter lacks a contract.
Distinguish SDK validation from backend semantics. For example, a quantile is
normally in [0, 1], but a backend may define results outside that interval;
the reference does not claim that every recommended range is rejected locally.
All builder composition returns a new shared expression. Client requests perform
I/O and configuration objects have their own mutability contracts.
vm_only marks a MetricsQL-only method; prom_only marks a PromQL-only method.
prom_experimental requires an explicit Prometheus feature opt-in. A missing
badge does not promise every argument form works in both languages: Rust checks
the complete expression at build time. See language support.
Main entry points
| Entry point | Purpose |
|---|---|
QueryBuilder | Factories, immutable composition and .build(mode) |
DatabaseClient | Query, metadata and VictoriaMetrics ingestion requests |
PrometheusConfig | Standard Prometheus endpoints |
VMSingleConfig | VictoriaMetrics single-node endpoints |
VMClusterConfig | VictoriaMetrics cluster endpoints and tenant selection |
HttpClientOptions | Timeouts, headers and custom transports |
register_config, get_config, set_default_instance | Optional named configuration registry |
MetricsQueryResult, MetricsInsertData, TimeValue | Client result, ingestion and time contracts |
Start with the building guide or client guide for connected examples. The builder source and client source remain available when reading this document on GitHub.
Choose an API category
Start a typed expression and render it with explicit dialect and resource limits.
11 methodsSelectors & filters ↗Choose metrics and attach literal label constraints.
7 methodsAggregation & grouping ↗Reduce across series and choose one grouping strategy.
42 methodsOperators & matching ↗Compose arithmetic, comparisons and vector matching.
38 methodsTime & subqueries ↗Set windows, evaluation time, offsets and subquery resolution.
17 methodsRates & window statistics ↗Compute rates and summaries over each series' lookbehind window.
35 methodsMetricsQL rollups ↗Use VictoriaMetrics-specific sample statistics and rollup variants.
50 methodsMath, sorting & histograms ↗Transform values, extract calendar fields and estimate histogram statistics.
55 methodsLabel operations ↗Transform output labels without modifying source expressions.
19 methodsMetricsQL transforms ↗Shape complete query intervals, fill gaps and work with histogram buckets.
40 methodsMetricsQL templates ↗Define scoped immutable values and reusable expression templates.
4 methodsValidation & diagnostics ↗Inspect shared graph structure and bounded rendered source spans.
6 methodsClient & requests ↗Execute saved queries, read metadata and manage sync/async transports.
24 methodsConnection configuration ↗Choose endpoints, tenant routing, timeouts and transport options.
35 methodsFind a method across all categories
QueryBuilder
__init__Factories & buildingabsMath, sorting & histogramsabsentMath, sorting & histogramsabsent_over_timeRates & window statisticsacosMath, sorting & histogramsacoshMath, sorting & histogramsaddOperators & matchingaggr_over_timeMetricsQL rollupsaggregateAggregation & groupingaliasLabel operationsanalyzeValidation & diagnosticsanchoredTime & subqueriesand_Operators & matchinganyAggregation & groupingascent_over_timeMetricsQL rollupsasinMath, sorting & histogramsasinhMath, sorting & histogramsatTime & subqueriesatanMath, sorting & histogramsatan2Operators & matchingatanhMath, sorting & histogramsavgAggregation & groupingavg_over_timeRates & window statisticsbetweenOperators & matchingbitmap_andMetricsQL transformsbitmap_orMetricsQL transformsbitmap_xorMetricsQL transformsboolOperators & matchingbottomkAggregation & groupingbottomk_avgAggregation & groupingbottomk_lastAggregation & groupingbottomk_maxAggregation & groupingbottomk_medianAggregation & groupingbottomk_minAggregation & groupingbuckets_limitMetricsQL transformsbuildFactories & buildingbyAggregation & groupingceilMath, sorting & histogramschangesRates & window statisticschanges_prometheusMetricsQL rollupsclampMath, sorting & histogramsclamp_maxMath, sorting & histogramsclamp_minMath, sorting & histogramscosMath, sorting & histogramscoshMath, sorting & histogramscountAggregation & groupingcount_eq_over_timeMetricsQL rollupscount_gt_over_timeMetricsQL rollupscount_le_over_timeMetricsQL rollupscount_ne_over_timeMetricsQL rollupscount_over_timeRates & window statisticscount_valuesAggregation & groupingcount_values_over_timeMetricsQL rollupsday_of_monthMath, sorting & histogramsday_of_weekMath, sorting & histogramsday_of_yearMath, sorting & histogramsdays_in_monthMath, sorting & histogramsdebugValidation & diagnosticsdebug_positionsValidation & diagnosticsdecreases_over_timeMetricsQL rollupsdefaultOperators & matchingdefault_rollupMetricsQL rollupsdegMath, sorting & histogramsdeltaRates & window statisticsdelta_prometheusMetricsQL rollupsderivRates & window statisticsderiv_fastMetricsQL rollupsdescent_over_timeMetricsQL rollupsdistinctAggregation & groupingdistinct_over_timeMetricsQL rollupsdivOperators & matchingdouble_exponential_smoothingRates & window statisticsdrop_common_labelsLabel operationsdrop_empty_seriesMetricsQL transformsduration_over_timeMetricsQL rollupsendTime & subquerieseqOperators & matchingeq_anyOperators & matchingexpMath, sorting & histogramsfillOperators & matchingfill_leftOperators & matchingfill_rightOperators & matchingfilterSelectors & filtersfirst_over_timeRates & window statisticsfloorMath, sorting & histogramsfrom_durationFactories & buildingfrom_endTime & subqueriesfrom_labelsFactories & buildingfrom_metricFactories & buildingfrom_nowTime & subqueriesfrom_numeric_literalFactories & buildingfrom_scalarFactories & buildingfrom_startTime & subqueriesfrom_stringFactories & buildingfrom_timeTime & subqueriesfrom_tupleFactories & buildingfunctionFactories & buildinggeOperators & matchinggeomeanAggregation & groupinggeomean_over_timeMetricsQL rollupsgroupAggregation & groupinggroup_leftOperators & matchinggroup_left_allOperators & matchinggroup_rightOperators & matchinggroup_right_allOperators & matchinggtOperators & matchinghistogramAggregation & groupinghistogram_avgMath, sorting & histogramshistogram_countMath, sorting & histogramshistogram_fractionMath, sorting & histogramshistogram_over_timeMetricsQL rollupshistogram_quantileMath, sorting & histogramshistogram_quantilesMetricsQL transformshistogram_shareMetricsQL transformshistogram_stddevMath, sorting & histogramshistogram_stdvarMath, sorting & histogramshistogram_sumMath, sorting & histogramshoeffding_bound_lowerMetricsQL rollupshoeffding_bound_upperMetricsQL rollupsholt_wintersRates & window statisticshourMath, sorting & histogramsideltaRates & window statisticsiderivMetricsQL rollupsif_Operators & matchingifnotOperators & matchingignoringOperators & matchingincreaseRates & window statisticsincrease_prometheusMetricsQL rollupsincrease_pureMetricsQL rollupsincreases_over_timeMetricsQL rollupsinfoMath, sorting & histogramsintegrateMetricsQL rollupsinterpolateMetricsQL transformsirateRates & window statisticskeep_last_valueMetricsQL transformskeep_metric_namesLabel operationskeep_next_valueMetricsQL transformslabel_copyLabel operationslabel_delLabel operationslabel_graphite_groupLabel operationslabel_joinLabel operationslabel_keepLabel operationslabel_lowercaseLabel operationslabel_mapLabel operationslabel_matchLabel operationslabel_mismatchLabel operationslabel_moveLabel operationslabel_replaceLabel operationslabel_setLabel operationslabel_transformLabel operationslabel_uppercaseLabel operationslabel_valueLabel operationslabels_equalLabel operationslagMetricsQL rollupslast_over_timeRates & window statisticsleOperators & matchinglifetimeMetricsQL rollupslimitAggregation & groupinglimit_offsetMetricsQL transformslimit_ratioAggregation & groupinglimitkAggregation & groupinglnMath, sorting & histogramslog10Math, sorting & histogramslog2Math, sorting & histogramsltOperators & matchingmadAggregation & groupingmad_over_timeRates & window statisticsmaxAggregation & groupingmax_ofMath, sorting & histogramsmax_over_timeRates & window statisticsmedianAggregation & groupingmedian_over_timeRates & window statisticsminAggregation & groupingmin_ofMath, sorting & histogramsmin_over_timeRates & window statisticsminuteMath, sorting & histogramsmodOperators & matchingmodeAggregation & groupingmode_over_timeRates & window statisticsmonthMath, sorting & histogramsmoving_averageRates & window statisticsmulOperators & matchingneOperators & matchingne_allOperators & matchingnegativeOperators & matchingnowTime & subqueriesoffsetTime & subqueriesonOperators & matchingor_Operators & matchingor_selectorSelectors & filtersoutlier_iqr_over_timeMetricsQL rollupsoutliers_iqrAggregation & groupingoutliers_madAggregation & groupingoutlierskAggregation & groupingparenthesizeOperators & matchingpositiveOperators & matchingpowOperators & matchingpredict_linearRates & window statisticspresent_over_timeRates & window statisticsprometheus_bucketsMetricsQL transformsquantileAggregation & groupingquantile_over_timeRates & window statisticsquantilesAggregation & groupingquantiles_over_timeMetricsQL rollupsquery_rangeTime & subqueriesradMath, sorting & histogramsrandMetricsQL transformsrand_exponentialMetricsQL transformsrand_normalMetricsQL transformsrangeTime & subqueriesrange_avgMetricsQL transformsrange_firstMetricsQL transformsrange_lastMetricsQL transformsrange_linear_regressionMetricsQL transformsrange_madMetricsQL transformsrange_maxMetricsQL transformsrange_medianMetricsQL transformsrange_minMetricsQL transformsrange_normalizeMetricsQL transformsrange_over_timeMetricsQL rollupsrange_quantileMetricsQL transformsrange_stddevMetricsQL transformsrange_stdvarMetricsQL transformsrange_sumMetricsQL transformsrange_trim_outliersMetricsQL transformsrange_trim_spikesMetricsQL transformsrange_trim_zscoreMetricsQL transformsrange_zscoreMetricsQL transformsrateRates & window statisticsrate_over_sumRates & window statisticsrate_prometheusMetricsQL rollupsreferenceMetricsQL templatesremove_resetsMetricsQL transformsresetsRates & window statisticsrollupRates & window statisticsrollup_candlestickMetricsQL rollupsrollup_deltaMetricsQL rollupsrollup_derivMetricsQL rollupsrollup_increaseMetricsQL rollupsrollup_rateRates & window statisticsrollup_scrape_intervalMetricsQL rollupsroundMath, sorting & histogramsruMetricsQL transformsrunning_avgMetricsQL transformsrunning_maxMetricsQL transformsrunning_minMetricsQL transformsrunning_sumMetricsQL transformsscalarMath, sorting & histogramsscrape_intervalMetricsQL rollupssgnMath, sorting & histogramsshareAggregation & groupingshare_eq_over_timeMetricsQL rollupsshare_gt_over_timeMetricsQL rollupsshare_le_over_timeMetricsQL rollupssinMath, sorting & histogramssinhMath, sorting & histogramssmooth_exponentialMath, sorting & histogramssmoothedTime & subqueriessortMath, sorting & histogramssort_by_labelMath, sorting & histogramssort_by_label_descMath, sorting & histogramssort_by_label_numericMath, sorting & histogramssort_by_label_numeric_descMath, sorting & histogramssort_descMath, sorting & histogramssqrtMath, sorting & histogramsstale_samples_over_timeMetricsQL rollupsstartTime & subqueriesstart_timestampTime & subqueriesstddevAggregation & groupingstddev_over_timeRates & window statisticsstdvarAggregation & groupingstdvar_over_timeRates & window statisticsstepTime & subqueriessubOperators & matchingsubqueryTime & subqueriessumAggregation & groupingsum2Aggregation & groupingsum2_over_timeMetricsQL rollupssum_eq_over_timeMetricsQL rollupssum_gt_over_timeMetricsQL rollupssum_le_over_timeMetricsQL rollupssum_over_timeRates & window statisticstanMath, sorting & histogramstanhMath, sorting & histogramstemplateMetricsQL templatestemplate_callMetricsQL templatestfirst_over_timeMetricsQL rollupstimeTime & subqueriestimestampMath, sorting & histogramstimestamp_with_nameMetricsQL rollupstimezone_offsetMetricsQL transformstlast_change_over_timeMetricsQL rollupstlast_over_timeMetricsQL rollupstmax_over_timeMetricsQL rollupstmin_over_timeMetricsQL rollupsto_debug_jsonValidation & diagnosticstopkAggregation & groupingtopk_avgAggregation & groupingtopk_lastAggregation & groupingtopk_maxAggregation & groupingtopk_medianAggregation & groupingtopk_minAggregation & groupingtrim_lowerOperators & matchingtrim_upperOperators & matchingts_of_first_over_timeRates & window statisticsts_of_last_over_timeRates & window statisticsts_of_max_over_timeRates & window statisticsts_of_min_over_timeRates & window statisticsttfMetricsQL transformsunionOperators & matchingunlessOperators & matchingvalidateValidation & diagnosticsvectorFactories & buildingvisualize_positionsValidation & diagnosticswhereSelectors & filterswhere_eqSelectors & filterswhere_neSelectors & filterswhere_not_regexSelectors & filterswhere_regexSelectors & filterswith_MetricsQL templateswithoutAggregation & groupingyearMath, sorting & histogramszscoreAggregation & groupingzscore_over_timeRates & window statistics
DatabaseClient
__init__Client & requestsacloseClient & requestsasync_clientClient & requestsclientClient & requestscloseClient & requestsclosedClient & requestsget_connection_infoClient & requestshealthClient & requestshealth_asyncClient & requestsinsertClient & requestsinsert_asyncClient & requestsinsert_base_urlClient & requestslabel_valuesClient & requestslabel_values_asyncClient & requestslabelsClient & requestslabels_asyncClient & requestsqueryClient & requestsquery_asyncClient & requestsquery_rangeClient & requestsquery_range_asyncClient & requestsselect_base_urlClient & requestsseriesClient & requestsseries_asyncClient & requestsstorage_base_urlClient & requests
PrometheusConfig
__init__Connection configurationdb_typeConnection configurationget_connection_infoConnection configurationget_insert_url_baseConnection configurationget_query_url_baseConnection configurationhttp_optionsConnection configurationhttp_options_dictConnection configurationset_http_optionsConnection configurationupdate_http_optionsConnection configurationvalidateConnection configuration
VMSingleConfig
__init__Connection configurationdb_typeConnection configurationget_connection_infoConnection configurationget_insert_url_baseConnection configurationget_query_url_baseConnection configurationhttp_optionsConnection configurationhttp_options_dictConnection configurationset_http_optionsConnection configurationupdate_http_optionsConnection configurationvalidateConnection configuration
VMClusterConfig
__init__Connection configurationdb_typeConnection configurationget_connection_infoConnection configurationget_insert_url_baseConnection configurationget_query_url_baseConnection configurationhttp_optionsConnection configurationhttp_options_dictConnection configurationset_http_optionsConnection configurationupdate_http_optionsConnection configurationvalidateConnection configuration