Python Package Examples

Retrieve all additions

This script will retrieve all additions from the autocompletes list for a given document group save them to a local CSV file.

import propertysync

# login to propertysync 
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# get all additions
additions = psync.get_autocompletes("addition")

# save to a local CSV file, without including the two additions that were removed above
with open("additions.csv", "w") as f:
    for addition in additions:
        f.write(f"{addition['id']},{addition['value']}\n")

Retrieve all additions, but filter some of the results

Same as above, but in this case we will also remove some of the additions from the list before saving to a local CSV file.

import propertysync

# login to propertysync 
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# get all additions
additions = psync.get_autocompletes("addition")

# In some cases, you may want to limit the additions that you post to. You can optionally 
# filter the list here before saving. To remove one or more additions from the list, you 
# might do the following:

# remove an addition from the list where 'value' is equal to 'REMOVE_THIS_ADDITION'
additions = [addition for addition in additions if addition['value'] != 'REMOVE_THIS_ADDITION']

# remove another one where the 'value' is equal to 'REMOVE_THIS_ADDITION_TOO'
additions = [addition for addition in additions if addition['value'] != 'REMOVE_THIS_ADDITION_TOO']

# save to a local CSV file, without including the two additions that were removed above
with open("additions.csv", "w") as f:
    for addition in additions:
        f.write(f"{addition['id']},{addition['value']}\n")

Retrieve all land validations

This script will retrieve all of the land validations for a given document group and save to a local json file

import propertysync
import json

# login to propertysync
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# get all validations
validations = psync.get_landvalidations()

# save to a local json file
with open("validations.json", "w") as f:
    f.write(json.dumps(validations, indent=4))

Verify batch additions

This script will look at a local copy of a batch file, will loop through all documents and all subdivisionLegal structures within each document and will verify that the addition name exists within the autocompletes list of all additions for that document group. This will prevent misposting documents to additions that don't exist in the plant.

import propertysync
import os, sys, json

# if an argument is passed, this is the batch file. Otherwise exit with help
if len(sys.argv) < 2:
    print("Usage: python verify_batch_additions.py batch_file.json")
    sys.exit(1)

# if the file exists, open it and read json into a batch_json variable
if os.path.exists(sys.argv[1]):
    with open(sys.argv[1], "r") as f:
        batch_json = json.load(f)
else:
    print("Batch file does not exist")
    sys.exit(1)

# login to propertysync using saved credentials
psync = propertysync.ApiClient(email='YOUR_EMAIL_HERE',password='YOUR_PASSWORD_HERE',document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# get all additions from the document group
print ("Getting autocompletes for document group %s" % document_group_id)
additions = psync.get_autocompletes("addition")

# create a list of additions from the autocompletes list containing only the addition value (name)
additions_list = [addition["value"] for addition in additions]

# loop through the batch and verify that each addition exists in the autocompletes list
for doc in batch_json["documents"]:
    for legal in doc["json"]["subdivisionLegal"]:
        addition = legal["addition"]
        if addition not in additions_list:
            print("Missing addition: '%s'" % addition)
            # if there is a doc id, print it
            if "id" in doc:
                print("From document: '%s'" % doc["id"])
            print("Instrument number: '%s'" % doc["json"]["instrumentNumber"])
            print("---------------------------------")

Search for documents by subdivision

This script will search for documents having a specific addition and will push the results into a batch, it will then retrieve the batch for modification and will save the batch to a local file.

import propertysync
import json

# login to propertysync
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# create a search object
search = propertysync.Search()

# add an addition to your search parameters
search.add_subdivision(addition="YOUR_ADDITION_HERE")

# run the search and if any results are returned, create a temporary batch
# once the batch finishes hydrating, retrieve it and delete it from indexing
batch_json = psync.run_search_and_create_batch(search.get_query())

# save the batch json to a local file
with open("batch.json", "w") as f:
    f.write(json.dumps(batch_json, indent=4))

This script will submit a local batch file to the PropertySync indexing system and once the batch documents have been processed, will save the batch to search (live plant).

import propertysync
import json

# login to propertysync
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# load a batch file into memory
with open('batch.json', 'r') as f:
    batch_json = json.load(f)

# submit the batch to propertysync, and save to search
# depending on the size of the batch, this may take a while
# by default, this will check the status of the batch every 2 seconds
# to ensure that all documents have been processed before it
# saves to search and returns
batch = psync.create_batch_from_json(batch_json, save_to_search=True)

# print the details of the batch
print (batch)

Verify batches sent

Verify that all documents in a batch have been submitted to search (made live in the plant), and/or automate the process of saving the batch to search for a particular user.

import propertysync

# login to propertysync
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# get a list of all batches
batches = psync.get_batches()

# loop through all batches to find those created by a particular user
for batch in batches:
    if batch['createdBy'] == 'Jim Smith':
        # check if the batch was submitted to search (made live in the plant)
        if batch['numOfDocs'] > 0 and batch['numOfDocs'] != batch['numOfCompletedDocs']:
            # this batch still has docs that have not yet been submitted to the plant, send them
            print ('Batch {} has {} docs that have not been submitted to search'.format(batch['name'], batch['numOfDocs'] - batch['numOfCompletedDocs']))
            
            # optionally, you can try to save the batch to search
            psync.save_batch_to_search(batch['id'])

Change addition name

This script will search for documents having a specific addition and will push the results into a batch, it will then retrieve the batch for modification and will change the addition name for all documents in the batch, then push the batch back to the indexing system.

import propertysync

# login to propertysync
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# create a search object
search = propertysync.Search()

# add an addition to your search parameters
search.add_subdivision(addition="ABIGAIL FARMS")

# run the search and if any results are returned, create a temporary batch
# once the batch finishes hydrating, retrieve it but do not delete it (we're going to update it)
batch_json = psync.run_search_and_create_batch(search.get_query(), batch_name='ABIGAIL FARMS', delete_batch=False)

# load the batch into our Batch object
batch = propertysync.Batch(batch_json)

# change the addition name on any matching documents from "ABIGAIL FARMS" to "ABIGAIL FARMS 2"
batch.replace("$.subdivisionLegal[?(@.addition=='ABIGAIL FARMS')].addition", "ABIGAIL FARMS 2")

# save the batch back to propertysync
psync.update_batch_from_json(batch.get_json())

Convert and send a TitleSearch batch

This script will convert a TitleSearch batch file to PropertySync format and then submit it to the PropertySync indexing system.

import propertysync

# login to propertysync
psync = propertysync.ApiClient(document_group_id='YOUR_DOCUMENT_GROUP_ID_HERE')

# create a batch object
batch = propertysync.Batch()

# load a title search batch from a file
batch.load_from_titlesearch_batch('titlesearch_batch.txt')

# save the batch to propertysync
psync.create_batch_from_json(batch.get_json())
Last Updated: