feat: add Python wrapper to run Synthea programmatically (#951) #1570
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a lightweight Python wrapper to support programmatic usage of the Synthea CLI. The wrapper allows users to generate patients from within Python scripts by passing parameters such as
state,age,gender,patients, and a custommodule. It also parses the FHIR output and returns only validPatientBundles.Related Issue
#951
Motivation
Currently, the only way to run Synthea is by invoking
run_syntheafrom the command line. This wrapper enables a Pythonic interface for running Synthea in notebooks, scripts, and larger data processing workflows. It helps improve integration with Python-based pipelines.Implementation Details
SyntheaGeneratorclass insidescripts/python_wrapper/synthea_wrapper.pyrun_synthea(Unix) orrun_synthea.bat(Windows)-p,-a,-g, and-mBundleJSON and returns only those containingPatiententriesoutput/fhir/before each runsave()methodscripts/python_wrapper/to avoid interfering with Java buildTesting
Manual testing was done via
example.py. Verified that:save()Next Steps (Optional)
scripts/python_wrapper/testsPlease feel free to suggest structural or naming changes. Happy to revise based on feedback!