Package: housecanary
TheHouseCanaryAPI Python Client provides an easy interface to call the HouseCanary API.API documentationFull documentation is available athttps://api-docs.housecanary.comInstallationTo install:pip install housecanaryBasic Usageimporthousecanaryclient=housecanary.ApiClient("my_api_key","my_api_secret")result=client.property.value(("10216 N Willow Ave","64157"))# result is an instance of housecanary.response.Responseprintresult.json()AuthenticationWhen you create an instance of an ApiClient, you need to give it your
API key and secret. You can manage these in your settings page athttps://valuereport.housecanary.com/#/settings/api-settings.You can pass these values to the ApiClient constructor:client=housecanary.ApiClient("my_api_key","my_api_secret")Alternatively, instead of passing in your key and secret to the
constructor, you can store them in the following environment variables:HC_API_KEYHC_API_SECRETCreating an instance of ApiClient with no arguments will read your key
and secret from those environment variables:client=housecanary.ApiClient()Usage DetailsEndpoint methodsThe ApiClient class provides a few wrappers which contain
various methods for calling the different API endpoints.The property wrapper is used for calling the Analytics API Property endpoints as well
as the Value Report and Rental Report endpoints.The block wrapper is used for calling the Analytics API Block endpoints.The zip wrapper is used for calling the Analytics API Zip endpoints.The msa wrapper is used for calling the Analytics API MSA endpoints.Property EndpointsAnalytics API Property Endpoints:block_histogram_bathsblock_histogram_bedsblock_histogram_building_areablock_histogram_valueblock_histogram_value_sqftblock_rental_value_distributionblock_value_distributionblock_value_tsblock_value_ts_historicalblock_value_ts_forecastcensusdetailsfloodltvltv_detailsmortgage_lienmsa_detailsmsa_hpi_tsmsa_hpi_ts_forecastmsa_hpi_ts_historicalnodowner_occupiedrental_valuerental_value_within_blocksales_historyschoolvaluevalue_forecastvalue_within_blockzip_detailszip_hpi_forecastzip_hpi_historicalzip_hpi_tszip_hpi_ts_forecastzip_hpi_ts_historicalzip_volatilitycomponent_mgetValue Report API Endpoint:value_reportRental Report API Endpoint:rental_reportArgs:All of the Analytics API property endpoint methods take andataargument.datacan be in the following forms:A dict like:{"address":"82 County Line Rd","zipcode":"72173","meta":"someID"}Or{"address":"82 County Line Rd","city":"San Francisco","state":"CA","meta":"someID"}Or{"slug":"123-Example-St-San-Francisco-CA-94105"}A list of dicts as specified above:[{"address":"82 County Line Rd","zipcode":"72173","meta":"someID"},{"address":"43 Valmonte Plaza","zipcode":"90274","meta":"someID2"}]A single string representing a slug:"123-Example-St-San-Francisco-CA-94105"A tuple in the form of (address, zipcode, meta) like:("82 County Line Rd","72173","someID")A list of (address, zipcode, meta) tuples like:[("82 County Line Rd","72173","someID"),("43 Valmonte Plaza","90274","someID2")]Using a tuple only supports address, zipcode and meta. To specify city, state, unit or slug,
please use a dict.The “meta” field is always optional.The available keys in the dict are:address (required if no slug)slug (required if no address)zipcode (optional)unit (optional)city (optional)state (optional)meta (optional)client_value (optional, forvalue_within_blockandrental_value_within_block)client_value_sqft (optional, forvalue_within_blockandrental_value_within_block)All of the property endpoint methods return a PropertyResponse object
(or ValueReportResponse or RentalReportResponse) or
the output of a custom OutputGenerator if one was specified in the constructor.Examples:client=housecanary.ApiClient()result=client.property.value([("10216 N Willow Ave","64157"),("82 County Line Rd","72173")])result=client.property.value({"address":"10216 N Willow Ave","city":"San Francisco","state":"CA"})result=client.property.value("123-Example-St-San-Francisco-CA-94105")Component_mget endpointYou may want to retrieve data from multiple Analytics API endpoints in one request.
In this case, you can use thecomponent_mgetmethod.
Thecomponent_mgetmethod takes anaddress_dataargument just like the other endpoint methods.
Pass in a list of Analytics API property endpoint names as the second argument.
Note thatvalue_reportandrental_reportcannot be included.Example:client=housecanary.ApiClient()result=client.property.component_mget(("10216 N Willow Ave","64157"),["property/school","property/census","property/details"])Value Report:Thevalue_reportmethod behaves differently than the other endpoint
methods. It only supports one address at a time, and it takes some
extra, optional parameters:Args:address(str)zipcode(str)Kwargs:report_type- “full” or “summary”. Optional. Default is “full”format_type- “json”, “pdf”, “xlsx” or “all”. Optional. Default is “json”Example:client=housecanary.ApiClient()# get Value Report in JSON format with "summary" report_type.result=client.property.value_report("10216 N Willow Ave","64157","summary","json")# print the JSON outputprintresult.json()# get Value Report in PDF format with "full" report_type.result=client.property.value_report("10216 N Willow Ave","64157",format_type="pdf")# result is binary data of the PDF.Rental Report:Therental_reportmethod is for calling the Rental Report API. It only supports one address at a time.Args:address(str)zipcode(str)Kwargs:format_type- “json”, “xlsx” or “all”. Optional. Default is “json”Learn more about the various endpoints in theAPI docs.Block EndpointsAnalytics API Block Endpoints:histogram_bathshistogram_bedshistogram_building_areahistogram_valuehistogram_value_sqftrental_value_distributionvalue_distributionvalue_tsvalue_ts_forecastvalue_ts_historicalcomponent_mgetArgs:All of the Analytics API block endpoints take ablock_dataargument.block_datacan be in the following forms:A dict with ablock_idlike:{"block_id":"060750615003005","meta":"someId"}For histogram endpoints you can include thenum_binskey:{"block_id":"060750615003005","num_bins":5,"meta":"someId"}For time series and distribution endpoints you can include theproperty_typekey:{"block_id":"060750615003005","property_type":"SFD","meta":"someId"}A list of dicts as specified above:[{"block_id":"012345678901234","meta":"someId"},{"block_id":"012345678901234","meta":"someId2}]A single string representing ablock_id:"012345678901234"A list ofblock_idstrings:["012345678901234","060750615003005"]The “meta” field is always optional.Seehttps://api-docs.housecanary.com/#analytics-api-block-levelfor more details
on the available parameters such asnum_binsandproperty_type.All of the block endpoint methods return a BlockResponse,
or the output of a custom OutputGenerator if one was specified in the constructor.Examples:client=housecanary.ApiClient()result=client.block.histogram_baths("060750615003005")result=client.block.histogram_baths({"block_id":"060750615003005","num_bins":5})result=client.block.value_ts({"block_id":"060750615003005","property_type":"SFD"})result=client.block.value_ts([{"block_id":"060750615003005","property_type":"SFD"},{"block_id":"012345678901234","property_type":"SFD"}])result=client.block.value_distribution(["012345678901234","060750615003005"])Zip EndpointsAnalytics API Zip Endpoints:detailshpi_forecasthpi_historicalhpi_tshpi_ts_forecasthpi_ts_historicalvolatilitycomponent_mgetArgs:All of the Analytics API zip endpoints take azip_dataargument.zip_datacan be in the following forms:A dict with azipcodelike:{"zipcode":"90274","meta":"someId"}A list of dicts as specified above:[{"zipcode":"90274","meta":"someId"},{"zipcode":"01960","meta":"someId2}]A single string representing azipcode:"90274"A list ofzipcodestrings:["90274","01960"]The “meta” field is always optional.All of the zip endpoint methods return a ZipCodeResponse,
or the output of a custom OutputGenerator if one was specified in the constructor.Examples:client=housecanary.ApiClient()result=client.zip.details("90274")result=client.zip.details({"zipcode":"90274","meta":"someId"})result=client.zip.details([{"zipcode":"90274","meta":"someId"},{"zipcode":"01960","meta":"someId2"}])result=client.zip.details(["90274","01960"])MSA EndpointsAnalytics API MSA Endpoints:detailshpi_tshpi_ts_forecasthpi_ts_historicalcomponent_mgetArgs:All of the Analytics API MSA endpoints take anmsa_dataargument.msa_datacan be in the following forms:A dict with anmsalike:{"msa":"41860","meta":"someId"}A list of dicts as specified above:[{"msa":"41860","meta":"someId"},{"msa":"40928","meta":"someId2}]A single string representing amsa:"41860"A list ofmsastrings:["41860","40928"]The “meta” field is always optional.All of the msa endpoint methods return an MsaResponse,
or the output of a custom OutputGenerator if one was specified in the constructor.Examples:client=housecanary.ApiClient()result=client.msa.details("41860")result=client.msa.details({"msa":"90274","meta":"someId"})result=client.msa.details([{"msa":"41860","meta":"someId"},{"msa":"40928","meta":"someId2"}])result=client.msa.details(["41860","40928"])Response ObjectsResponseResponse is a base class for encapsulating an HTTP response from the
HouseCanary API.Properties:endpoint_name- Gets the endpoint name of the original requestresponse- Gets the underlying response object.Methods:json()- Gets the body of the response from the API as json.has_object_error()- Returns true if any requested objects had
a business logic error, otherwise returns false.get_object_errors()- Gets a list of business error message
strings for each of the requested objects that had a business error.
If there was no error, returns an empty list.objects()- Overridden in subclasses.rate_limits- Returns a list of rate limit informationPropertyResponseA subclass of Response, this is returned for all property endpoints
except forvalue_reportandrental_report.Methods:objects()- Gets a list of Property objects for the requested
properties, each containing the object’s returned json data from the
API.properties()- An alias for the objects() method.BlockResponseA subclass of Response, this is returned for all block endpoints.Methods:objects()- Gets a list of Block objects for the requested
blocks, each containing the object’s returned json data from the
API.blocks()- An alias for the objects() method.ZipCodeResponseA subclass of Response, this is returned for all zip endpoints.Methods:objects()- Gets a list of ZipCode objects for the requested
zipcodes, each containing the object’s returned json data from the
API.zipcodes()- An alias for the objects() method.MsaResponseA subclass of Response, this is returned for all msa endpoints.Methods:objects()- Gets a list of Msa objects for the requested
msas, each containing the object’s returned json data from the
API.msas()- An alias for the objects() method.HouseCanaryObjectBase class for various types of objects returned from the HouseCanary
API. Currently, only the Property subclass is implemented.Properties:component_results- a list of ComponentResult objects that
contain data and error information for each endpoint requested for
this HouseCanaryObject.Methods:has_error()- Returns a boolean of whether there was a business
logic error fetching data for any components for this object.get_errors()- If there was a business error fetching data for
any components for this object, returns the error messages.PropertyA subclass of HouseCanaryObject, the Property represents a single
address and it’s returned data.Properties:addresszipcodezipcode_plus4address_fullcitycountry_fipslatlngstateunitmetaExample:result=client.property.value(("123 Main St","01234","meta information"))p=result.properties()[0]printp.address# "123 Main St"printp.zipcode# "01234"printp.meta# "meta information"value_result=p.component_results[0]printvalue_result.component_name# 'property/value'printvalue_result.api_code# 0printvalue_result.api_code_description# 'ok'printvalue_result.json_data# {u'value': {u'price_upr': 1575138.0, u'price_lwr': 1326125.0, u'price_mean': 1450632.0, u'fsd': 0.086}}printp.has_error()# Falseprintp.get_errors()# []BlockA subclass of HouseCanaryObject, the Block represents a single
block and it’s returned data.Properties:block_idproperty_typemetaExample:result=client.block.value_ts("060750615003005")b=result.blocks()[0]printb.block_id# "060750615003005"printb.meta# "meta information"value_result=b.component_results[0]printvalue_result.component_name# 'block/value_ts'printvalue_result.api_code# 0printvalue_result.api_code_description# 'ok'printvalue_result.json_data# [...data...]printb.has_error()# Falseprintb.get_errors()# []ZipCodeA subclass of HouseCanaryObject, the ZipCode represents a single
zipcode and it’s returned data.Properties:zipcodemetaExample:result=client.zip.details("90274")z=result.zipcodes()[0]printz.zipcode# "90274"printz.meta# "meta information"details_result=z.component_results[0]printdetails_result.component_name# 'zip/details'printdetails_result.api_code# 0printdetails_result.api_code_description# 'ok'printdetails_result.json_data# [...data...]printz.has_error()# Falseprintz.get_errors()# []MsaA subclass of HouseCanaryObject, the Msa represents a single
Metropolitan Statistical Area and it’s returned data.Properties:msametaExample:result=client.msa.details("41860")m=result.msas()[0]printm.msa# "41860"printm.meta# "meta information"details_result=m.component_results[0]printdetails_result.component_name# 'msa/details'printdetails_result.api_code# 0printdetails_result.api_code_description# 'ok'printdetails_result.json_data# [...data...]printm.has_error()# Falseprintm.get_errors()# []ValueReportResponseA subclass of Response, this is the object returned for thevalue_reportendpoint when “json” format_type is used. It simply
returns the JSON data of the Value Report.Example:result=client.property.value_report("123 Main St","01234")printresult.json()RentalReportResponseA subclass of Response, this is the object returned for therental_reportendpoint when “json” format_type is used. It simply
returns the JSON data of the Rental Report.Example:result=client.property.rental_report("123 Main St","01234")printresult.json()Command Line ToolsWhen you install this package, a couple command line tools are included and installed on your PATH.HouseCanary Analytics API ExportHouseCanary API Excel ConcatRunning TestsTo run the unit test suite:python setup.py nosetests --with-coverage --cover-package=housecanaryDuring unit tests, all API requests are mocked.
You can run the unit tests with real API requests by doing the following:UpdateURL_PREFIXinconstants.pyto point to a test or dev environmentObtain an account for that environment that has permissions to all API componentsObtain an API Key and Secret and put them inHC_API_KEYandHC_API_SECRETenvironment variablesRun the test suite as:HC_API_CALLS=true python setup.py nosetestsNote:This setting will be ignored and API requests will be mocked ifURL_PREFIXis pointing to Production.LicenseThis API Client Library is made available under the MIT License:The MIT License (MIT)Copyright (c) 2017 HouseCanary, IncPermission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.For the avoidance of doubt, the above license does not apply to
HouseCanary’s proprietary software code or APIs, or to any data,
analytics or reports made available by HouseCanary from time to time,
all of which may be licensed pursuant to a separate written agreement