Metadata-Version: 2.4
Name: mozilla-metric-config-parser
Version: 2026.7.1
Summary: Parses metric configuration files.
Author-email: Mozilla Corporation <fx-data-dev@mozilla.org>
Project-URL: Repository, https://github.com/mozilla/metric-hub/blob/main/lib/metric-config-parser
Project-URL: Documentation, https://github.com/mozilla/metric-hub/blob/main/lib/metric-config-parser
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: attrs
Requires-Dist: cattrs
Requires-Dist: Click
Requires-Dist: GitPython
Requires-Dist: jinja2
Requires-Dist: mozilla-nimbus-schemas>=2024.9.3
Requires-Dist: pytz
Requires-Dist: requests
Requires-Dist: toml
Provides-Extra: testing
Requires-Dist: coverage; extra == "testing"
Requires-Dist: jsonschema; extra == "testing"
Requires-Dist: mypy; extra == "testing"
Requires-Dist: pytest; extra == "testing"
Requires-Dist: pytest-cov; extra == "testing"
Requires-Dist: pytest-ruff; extra == "testing"
Requires-Dist: ruff; extra == "testing"
Requires-Dist: types-futures; extra == "testing"
Requires-Dist: types-protobuf; extra == "testing"
Requires-Dist: types-pytz; extra == "testing"
Requires-Dist: types-PyYAML; extra == "testing"
Requires-Dist: types-requests; extra == "testing"
Requires-Dist: types-setuptools; extra == "testing"
Requires-Dist: types-six; extra == "testing"
Requires-Dist: types-toml; extra == "testing"
Dynamic: license-file

# metric-config-parser

This package parses configuration files that are compatible with [jetstream](https://github.com/mozilla/jetstream) and [opmon](https://github.com/mozilla/opmon) compatible configuration files.

## Installation

`pip install mozilla-metric-config-parser`

## Templating in `from_expression`

A data source's `from_expression` supports two independent templating layers:

* `{dataset}` (single braces, Python `str.format`) is replaced with an app-specific dataset
  for Glean apps. If used, `default_dataset` is mandatory.
* `{{experiment.<attr>}}` (double braces, Jinja) is replaced with an attribute of the
  experiment the data source is being resolved for, e.g. `{{experiment.normandy_slug}}`,
  `{{experiment.start_date_str}}`, `{{experiment.end_date_str}}`,
  `{{experiment.last_enrollment_date_str}}`. This is only rendered when the expression
  actually references `experiment`, and is only available when resolving a data source for
  an experiment.

```toml
[data_sources.messaging_events]
from_expression = """(
    SELECT *
    FROM `moz-fx-data-shared-prod.fenix.events_stream`
    WHERE STARTS_WITH(extras.string.message_key, '{{experiment.normandy_slug}}:')
)"""
experiments_column_type = "none"
```

A literal brace can still be written by doubling it, e.g. `'{{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}}'`.

## Testing

### Pytest
```
pytest --ruff --ignore=metric_config_parser/tests/integration/
```

### Linting and formatting
```
ruff check metric_config_parser
ruff format --check metric_config_parser
mypy metric_config_parser
```
