Using opensafely-matching
System requirements
Requires Python 3.8+
Install with:
pip install opensafely-matching
Input data
This is expected to be provided in two files in one of the supported formats (.csv, .csv.gz or .arrow) - one for the case/exposed group and one for the population to be matched.
Use
In a python script
Matching is run by calling the match function with at least the required arguments, as per:
from osmatching import match, load_config, load_dataframe
config = load_config(
{
"matches_per_case": 3,
"index_date_variable": "index_date",
"match_variables": {
"sex": "category",
"age": 5
}
}
)
match(
case_df=load_dataframe("input_cases.arrow"),
match_df=load_dataframe("input_matches.arrow"),
match_config=load_config(config)
)
This matches 3 matches per case, on the variables sex, and age (±5 years) and produces output files in the default .arrow format.
Outputs:
output/matched_cases.arrow
output/matched_matches.arrow
output/matched_combined.arrow
output/matching_report.txt
From the command line
usage: match [-h] (--config CONFIG | --config-file CONFIG) [--cases CASES]
[--controls CONTROLS] [--output-format {arrow,csv.gz,csv}]
Matches cases to controls if provided with 2 datasets
options:
-h, --help show this help message and exit
--config CONFIG The configuration for the matching action (a JSON string)
--config-file CONFIG Path to the configuration JSON file for the matching action
--cases CASES Data file that contains the cases
--controls CONTROLS Data file that contains the cohort for cases
--output-format {arrow,csv.gz,csv}
Format for the output files
To run the above example from the command line:
match --cases input_cases.arrow --controls input_matches.arrow --config-file config.json
where config.json is a file containing additional arguments to match():
{
"matches_per_case": 3,
"match_variables": {
"sex": "category",
"age": 5
},
"index_date_variable": "indexdate"
}
Alternatively, pass config on the command line as a json string:
match \
--cases input_cases.arrow \
--controls input_matches.arrow \
--config '{"matches_per_case": 3, "match_variables": {"sex": "category", "age": 5}, "index_date_variable": "indexdate"}'
For configuration options, please see the reusable action documentation
Metadata
Release files for opensafely-matching 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opensafely_matching-1.2.3.tar.gz | 29.3 kB | Without provenance | Details for opensafely_matching-1.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opensafely_matching-1.2.3-py3-none-any.whl | Python 3 | none | any | Details for opensafely_matching-1.2.3-py3-none-any.whl |
Total release size: 57.1 kB
Release files / opensafely_matching-1.2.3.tar.gz
| Download URL | opensafely_matching-1.2.3.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8b5fbfffeef8c02ca8cf8f59aa67007b20540fe55c8b7abb1d94e52ee420131
|
|
BLAKE2b-256 checksum How to use checksums |
0b2ac8dcaab8ce9cae4e73cf7f87786bbb670c724a1a3ecd24932ea51333b859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / opensafely_matching-1.2.3-py3-none-any.whl
| Download URL | opensafely_matching-1.2.3-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97e55331bd13b90c3bbdad4230481cda0d6c49240fa14f52041491513a3abbdd
|
|
BLAKE2b-256 checksum How to use checksums |
80d154af815a9e9f2b9539986162393ea531248e26b76dcb64feeb7733734cfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for opensafely-matching 1.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.