Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 215 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,173 +1,301 @@
![TechSpecs Logo](https://i.imgur.com/JwSpZO8.jpg)
![TechSpecs Logo](https://i.imgur.com/JZ3GqAU.jpg)
<p align="center">
<img src="https://techspecs.io/big-logo-light.svg" alt="TechSpecs Logo" width="200" height="200">
</p>

# Introducing TechSpecs Python
# Introduction

This python library provides automatic access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, and more.
TechSpecs Python provides easy access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, monitors, TVs and more.

## API Key
# Database Stats

At TechSpecs, we are committed to providing the most comprehensive and up-to-date database of technical specifications for consumer electronics products. Here are some statistics on our current database:

Total number of products: 100,000+
- Brands: 400+
- Categories: 6 (Smartphones, Tablets, Smartwatches, Monitors, TVs, and Laptops)
- Technical specifications: Over 300 for each product, including dimensions, weight, display features, connectivity options, and more.
- Daily updates: We update our database on a daily basis to ensure that our API provides the most accurate and up-to-date technical specifications for the products you're interested in.

- Get an API key [here](https://developer.dashboard.techspecs.io/)
We take pride in providing a database that is comprehensive and reliable, and we are constantly working to expand and improve it. If you have any questions or issues, please don't hesitate to reach out to our support team for assistance.

## API Key

- [Signup](https://techspecs.io/) to get your TechSpecs API Key

## Requirements

- Python 3.6+


## Installation
![How to install TechSpecs](https://i.imgur.com/m9yxeWW.png)

```sh
pip install techspecs
```

## Usage

The library needs to be configured with your account's api key and base which is
available in your [TechSpecs Dashboard](https://developer.dashboard.techspecs.io/).
The library needs to be configured with your TechSpecs api key and base URL which is
available in your [TechSpecs Dashboard](https://techspecs.io/dashboard).

Set `techspecs_key` to your key value and `techspecs_base` to your base value.
Set `techspecs_api_key` to your key value and `techspecs_base_url` to your base value.

### Basic Search
#### Search for a device by specifying it's model name, version number or features
### Product Search

```python
# Search for a product by name, version or features
import techspecs
import json

# TechSpecs API Key
techspecs_key = "techspecs_api_key"
# TechSpecs API base URL
techspecs_base_url = "https://api.techspecs.io"

# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base}
techspecs_base = 'a8TD3mkN49fhg2y'
# TechSpecs API bearer token
techspecs_api_key = "your_techspecs_api_key"

query = {
'keyword': 'iPhone 13', # product name or version number to search
'category': 'all', # product category 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
}

# choose between "pretty" or "raw" mode for viewing response
response = techspecs.search(base, query, key, mode='pretty')
# Output mode ('raw' or 'pretty')
mode = 'pretty'

# Search for a product by name, version, or features
try:
response = techspecs.product_search(techspecs_base_url, query, techspecs_api_key, mode=mode)
print(response)
except Exception as e:
print(f"An error occurred: {e}")

# print the search results
print(response)

```

### Advanced Search
#### List all products by brand, category and release date

### Product Details

```python
# List all products by brand, category and release date
# Get the detailed specifications of a product
import techspecs

# TechSpecs API Key
techspecs_key = "techspecs_api_key"
# TechSpecs API base URL
techspecs_base_url = "https://api.techspecs.io"

# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base}
techspecs_base = "a8TD3mkN49fhg2y"
# TechSpecs API bearer token
techspecs_api_key = "your_techspecs_api_key"

# enter the page number to fetch results from
page = 1
# TechSpecs product ID
techspecs_product_id = "63e96260ff7af4b68a304e40"

# type in the name of the brand you're looking for or leave this field empty to see results from all brands
brand = ["Apple"]
# Query dictionary
query = {
"productId": techspecs_product_id
}

# type in the name of the category you're looking for or leave this field empty to see results from all categories
category = ["smartphone"]
# Output mode ('raw' or 'pretty')
mode = 'pretty'

# please provide a date range to narrow your search. Leave this field empty to fetch all results from all dates
date = {
"from": "2010-01-01", # YYYY-MM-DD
"to": "2022-03-15" # YYYY-MM-DD
}
try:
# Validate techspecs_product_id
if not isinstance(techspecs_product_id, str):
raise ValueError('TechSpecs Product ID should be a string.')

# Validate mode
if mode not in ['raw', 'pretty']:
raise ValueError('Invalid mode. Mode should be "raw" or "pretty".')

# Call TechSpecs API to get product details
response = techspecs.product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode=mode)

# Print the product details
print(response)
except Exception as e:
print(f"An error occurred: {e}")

# choose between "pretty" or "raw" mode for viewing response
response = techspecs.products(techspecs_base, brand, category, date, page, techspecs_key, mode='pretty')

# print the search results
print(response)
```

### Apple Machine ID Search
#### Search for Apple products by machine id

### List all categories
```python
# Search for an Apple product by machine id
import techspecs

# TechSpecs API Key
techspecs_key = "techspecs_api_key"
# TechSpecs API base URL
techspecs_base_url = "https://api.techspecs.io"

# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base}
techspecs_base = "a8TD3mkN49fhg2y"
# TechSpecs API bearer token
techspecs_api_key = "your_techspecs_api_key"

# machine id to search
machine_id = "iphone8,3"
# Output mode ('raw' or 'pretty')
mode = 'pretty'

# Define constants
DEFAULT_MODE = 'pretty'
VALID_MODES = ['pretty', 'raw']

# Validate parameters
def validate_parameters(mode=DEFAULT_MODE):
if mode not in VALID_MODES:
raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.')

# Validate search parameters
try:
validate_parameters(mode=mode)
except ValueError as e:
print(f"Invalid search parameters: {e}")
exit()

# Call TechSpecs API to get all categories
try:
response = techspecs.get_all_categories(techspecs_base_url, techspecs_api_key, mode=mode)
print(response)
except Exception as e:
print(f"An error occurred: {e}")

# choose between "pretty" or "raw" mode for viewing response
response = techspecs.apple_machine_id(techspecs_base, machine_id, techspecs_key, mode='pretty')

# print the specifications of the product
print(response)
```

### Product Details

### List all brands
```python
# Get the standardized specifications of a specified product
import techspecs

# TechSpecs API Key
techspecs_key = "techspecs_api_key"
# TechSpecs API base URL
techspecs_base_url = "https://api.techspecs.io"

# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base}
techspecs_base = "a8TD3mkN49fhg2y"
# TechSpecs API bearer token
techspecs_api_key = "your_techspecs_api_key"

# TechSpecs product id
techspecs_id = "6186b047987cda5f88311983"
# Output mode ('raw' or 'pretty')
mode = 'pretty'

# choose between "pretty" or "raw" mode for viewing response
response = techspecs.detail(techspecs_base, techspecs_id, techspecs_key, mode='pretty')
# Define function to validate parameters
def validate_parameters(mode):
if mode not in ['raw', 'pretty']:
raise ValueError(f'Invalid mode: {mode}. Mode should be one of ["raw", "pretty"].')

# Validate parameters
try:
validate_parameters(mode)
except ValueError as e:
print(f"Invalid parameters: {e}")
exit()

# Call TechSpecs API to get all brands
try:
response = techspecs.get_all_brands(techspecs_base_url, techspecs_api_key, mode=mode)
print(response)
except Exception as e:
print(f"An error occurred: {e}")

# print the specifications of the product
print(response)

```

### List all brands

### Advanced Search
```python
# List all products by brand, category and release date
import techspecs
import datetime

# TechSpecs API base URL
techspecs_base_url = "https://api.techspecs.io"

# TechSpecs API bearer token
techspecs_api_key = "your_techspecs_api_key"

# Output mode ('raw' or 'pretty')
mode = 'pretty'

# Set constants
DEFAULT_PAGE = 0
DEFAULT_MODE = 'pretty'
VALID_MODES = ['pretty', 'raw']

# Define function to validate date format
def is_valid_date(date_str):
try:
datetime.datetime.strptime(date_str, '%Y-%m-%d')
return True
except ValueError:
return False

# Define function to validate parameters
def validate_parameters(brand, category, date=None, page=DEFAULT_PAGE, mode=DEFAULT_MODE):
if not isinstance(brand, list):
raise ValueError('Brand should be a list.')

if not isinstance(category, list):
raise ValueError('Category should be a list.')

if date is not None:
if not isinstance(date, dict):
raise ValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".')
elif 'from' not in date or 'to' not in date:
raise ValueError('Invalid date format. Date dictionary should have keys "from" and "to".')
elif not is_valid_date(date['from']) or not is_valid_date(date['to']):
raise ValueError('Invalid date format. Date should be in the format YYYY-MM-DD.')

if not isinstance(page, int) or page < 0:
raise ValueError('Page should be a non-negative integer.')

if mode not in VALID_MODES:
raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.')

# Define search parameters
brand = ["Apple"]
category = ["Smartphones"]
date = {
"from": "2010-01-01",
"to": "2022-03-15"
}
page = 0

# TechSpecs API Key
techspecs_key = "techspecs_api_key"

# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base}
techspecs_base = "a8TD3mkN49fhg2y"
# Validate search parameters
try:
validate_parameters(brand, category, date=date, page=page, mode=mode)
except ValueError as e:
print(f"Invalid search parameters: {e}")
exit()

# choose between "pretty" or "raw" mode for viewing response
response = techspecs.brands(techspecs_base, techspecs_key, mode='pretty')

# print the list of all brands
print(response)
# Call TechSpecs API to get all products
try:
response = techspecs.get_all_products(techspecs_base_url, techspecs_api_key, brand, category, date, page, mode=mode)
print(response)
except Exception as e:
print(f"An error occurred: {e}")


```
### List all categories


### Machine ID Search
#### Search for Apple products by machine id
```python
# Search for an Apple product by machine id
import techspecs

# TechSpecs API Key
techspecs_key = "techspecs_api_key"
# TechSpecs API base URL
techspecs_base_url = "https://api.techspecs.io"

# TechSpecs API bearer token
techspecs_api_key = "your_techspecs_api_key"

# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6
machine_id = "iphone 11,6"

# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base}
techspecs_base = "a8TD3mkN49fhg2y"
# Output mode ('raw' or 'pretty')
mode = 'pretty'

# choose between "pretty" or "raw" mode for viewing response
response = techspecs.categories(techspecs_base, techspecs_key, mode='pretty')
# Look up the Apple machine by its serial number
try:
response = techspecs.machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode)
print(response)
except Exception as e:
print(f"An error occurred: {e}")

# print the list of all categories
print(response)

```

Expand Down
Loading