The Save Metadata to Files / Read Metadata from File functions will do what you require.
Lightroom provides a facility for writing library metadata out to XMP files alongside the original images, so it ought to be possible to write your program to look at those sidecar files and edit the existing data.
Metadata can be written out to files using the intuitively-named "Save Metadata to Files" command in the Metadata menu. The resulting XMP file is external to both the library as well as the original image's internal metadata. Individual XMP fields can then be manipulated programmatically (e.g. the
exif:GPSLatitude field). This avoids overwriting current metadata with old metadata at any point, and will also preserve edits made to the images in Lightroom as well as any metadata that was manually entered in the library. After editing the XMP, Lightroom can read the changes back into the library with the menu item "Read Metadata from File".
Caveat 1: Saving the library metadata out to the XMP file will overwrite an existing file in the same location. This is a good thing. This means that there isn't an easy way to have two sets of metadata in different states. As a programmer, having two metadata states may be handy for some fun tricks, but as a photographer I can personally say that I would much rather have the peace of mind that there only exists one state.
Caveat 2: The Lightroom API (as of ver. 6) does not appear to provide a convenient way of saving the current library metadata out to files before operating on them, nor a way of reading new metadata into the library when your program finishes. This means that there is no simple way to programmatically guarantee that your code will be operating on metadata files which share their state with the metadata in the Lightroom catalog. My impression is that this is a safeguard to keep Lightroom's library metadata state at the top of the hierarchy, as for many users the library will represent the authoritative state of the data.
The workaround: You may need to resign yourself to asking the user to manually save out the metadata before your program runs, and instructing the user to read in the updated metadata after completion. I am not a LR plugin programmer myself, but I have used several plugins which use this pattern, so it may well be what is necessary. Luckily this isn't a huge hassle in normal use, as the menu items "Save Metadata to File" and "Read Metadata from Files" are only one click away in the Metadata menu, and will probably just be used once after selecting all of the images to be included in the operation.