Package: techspecs
IntroductionTechSpecs Python provides easy access to the standardized technical specifications of the world's consumer electronics, including smartphones, tablets, smartwatches, laptops, monitors, TVs and more.DocumentationSee theTechSpecs API DocsAPI KeySignupto get your TechSpecs API KeyRequirementsPython 3.6+InstallationpipinstalltechspecsUsageThe library needs to be configured with your TechSpecs api key and base URL which is
available in yourTechSpecs Dashboard.Settechspecs_api_keyto your key value andtechspecs_base_urlto your base value.Product SearchSearch for a device by specifying it's model name, version number or features# Search for a product by name, version or featuresimporttechspecsimportjson# TechSpecs API base URLtechspecs_base_url="https://api.techspecs.io"# TechSpecs API bearer tokentechspecs_api_key="your_techspecs_api_key"query={'keyword':'iPhone 13',# product name or version number to search'category':'',# product category to search (e.g. 'Smartphones', 'Tablets', or leave empty to search all categories)'page':0# page number to fetch results from}# Output mode ('raw' or 'pretty')mode='pretty'# Search for a product by name, version, or featurestry:response=techspecs.product_search(techspecs_base_url,query,techspecs_api_key,mode=mode)print(response)exceptExceptionase:print(f"An error occurred:{e}")Product Details# Get the detailed specifications of a productimporttechspecs# TechSpecs API base URLtechspecs_base_url="https://api.techspecs.io"# TechSpecs API bearer tokentechspecs_api_key="your_techspecs_api_key"# TechSpecs product IDtechspecs_product_id="63e96260ff7af4b68a304e40"# Query dictionaryquery={"productId":techspecs_product_id}# Output mode ('raw' or 'pretty')mode='pretty'try:# Validate techspecs_product_idifnotisinstance(techspecs_product_id,str):raiseValueError('TechSpecs Product ID should be a string.')# Validate modeifmodenotin['raw','pretty']:raiseValueError('Invalid mode. Mode should be "raw" or "pretty".')# Call TechSpecs API to get product detailsresponse=techspecs.product_detail(techspecs_base_url,techspecs_product_id,techspecs_api_key,mode=mode)# Print the product detailsprint(response)exceptExceptionase:print(f"An error occurred:{e}")List all categoriesimporttechspecs# TechSpecs API base URLtechspecs_base_url="https://api.techspecs.io"# TechSpecs API bearer tokentechspecs_api_key="your_techspecs_api_key"# Output mode ('raw' or 'pretty')mode='pretty'# Define constantsDEFAULT_MODE='pretty'VALID_MODES=['pretty','raw']# Validate parametersdefvalidate_parameters(mode=DEFAULT_MODE):ifmodenotinVALID_MODES:raiseValueError(f'Invalid mode:{mode}. Mode should be one of{VALID_MODES}.')# Validate search parameterstry:validate_parameters(mode=mode)exceptValueErrorase:print(f"Invalid search parameters:{e}")exit()# Call TechSpecs API to get all categoriestry:response=techspecs.get_all_categories(techspecs_base_url,techspecs_api_key,mode=mode)print(response)exceptExceptionase:print(f"An error occurred:{e}")List all brandsimporttechspecs# TechSpecs API base URLtechspecs_base_url="https://api.techspecs.io"# TechSpecs API bearer tokentechspecs_api_key="your_techspecs_api_key"# Output mode ('raw' or 'pretty')mode='pretty'# Define function to validate parametersdefvalidate_parameters(mode):ifmodenotin['raw','pretty']:raiseValueError(f'Invalid mode:{mode}. Mode should be one of ["raw", "pretty"].')# Validate parameterstry:validate_parameters(mode)exceptValueErrorase:print(f"Invalid parameters:{e}")exit()# Call TechSpecs API to get all brandstry:response=techspecs.get_all_brands(techspecs_base_url,techspecs_api_key,mode=mode)print(response)exceptExceptionase:print(f"An error occurred:{e}")Advanced SearchList all products by brand, category and release date# List all products by brand, category and release dateimporttechspecsimportdatetime# TechSpecs API base URLtechspecs_base_url="https://api.techspecs.io"# TechSpecs API bearer tokentechspecs_api_key="your_techspecs_api_key"# Output mode ('raw' or 'pretty')mode='pretty'# Set constantsDEFAULT_PAGE=0DEFAULT_MODE='pretty'VALID_MODES=['pretty','raw']# Define function to validate date formatdefis_valid_date(date_str):try:datetime.datetime.strptime(date_str,'%Y-%m-%d')returnTrueexceptValueError:returnFalse# Define function to validate parametersdefvalidate_parameters(brand,category,date=None,page=DEFAULT_PAGE,mode=DEFAULT_MODE):ifnotisinstance(brand,list):raiseValueError('Brand should be a list.')ifnotisinstance(category,list):raiseValueError('Category should be a list.')ifdateisnotNone:ifnotisinstance(date,dict):raiseValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".')elif'from'notindateor'to'notindate:raiseValueError('Invalid date format. Date dictionary should have keys "from" and "to".')elifnotis_valid_date(date['from'])ornotis_valid_date(date['to']):raiseValueError('Invalid date format. Date should be in the format YYYY-MM-DD.')ifnotisinstance(page,int)orpage<0:raiseValueError('Page should be a non-negative integer.')ifmodenotinVALID_MODES:raiseValueError(f'Invalid mode:{mode}. Mode should be one of{VALID_MODES}.')# Define search parametersbrand=["Apple"]category=["Smartphones"]date={"from":"2010-01-01","to":"2022-03-15"}page=0# Validate search parameterstry:validate_parameters(brand,category,date=date,page=page,mode=mode)exceptValueErrorase:print(f"Invalid search parameters:{e}")exit()# Call TechSpecs API to get all productstry:response=techspecs.get_all_products(techspecs_base_url,techspecs_api_key,brand,category,date,page,mode=mode)print(response)exceptExceptionase:print(f"An error occurred:{e}")Machine ID SearchSearch for Apple products by machine id# Search for an Apple product by machine idimporttechspecs# TechSpecs API base URLtechspecs_base_url="https://api.techspecs.io"# TechSpecs API bearer tokentechspecs_api_key="your_techspecs_api_key"# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6machine_id="iphone 11,6"# Output mode ('raw' or 'pretty')mode='pretty'# Look up the Apple machine by its serial numbertry:response=techspecs.machine_id_search(techspecs_base_url,techspecs_api_key,machine_id,mode)print(response)exceptExceptionase:print(f"An error occurred:{e}")