Skip to main content

NSG class for making parts searches in Octopart using the Nexar API v4

Project description

NSG Parts Search

A class used for querying parts in Octopart using Nexar API v4.0.

The following class has all the needed methods required by NSG to create a query to Octopart.

This package is maintained and used by NSG, please refer to the licensing before using.


Table of content


Installation

Use the package manager pip to install nsg-parts-search.

pip install nsg-parts-search

Prerequisites

Use the application client ID and secret. Refer to the NSG Documentation.

Set environment variables CLIENT_ID and CLIENT_SECRET.

Usage

General example to get a response from a list of parts search:

from nsgsearch import *

# set credentials
clientId = os.environ['CLIENT_ID']
clientSecret = os.environ['CLIENT_SECRET']

# start the client
search = NSG_OctopartSearch()
search.setCredentials(clientId, clientSecret)
search.startClient()

# search for parts
parts_list = []
results = search.partsSearch(parts_list)

print(results)

Filtering Functions

Say that from a list of parts you want a table of the Manufacturer, Suppliers, Quantity and Price per unit in USD:

# loop through all parts
for part in parts_list:
    # enter just if the part number was found
    if results[part]['found']:
        part_data = results[part]['data']
        # get a table of prices for the part
        priceTable = search.partPricesTable(part_data)

Maybe now you want to get the lowest price from the table for that part number:

def get_lowest_price(table):
  price = table[0]['price']
  supplier = str()
  qty = int()
  for row in table:
      if row['price'] < price:
          price = row['price']
          supplier = row['supplier']
          qty = row['reqPurchase']

  return ([supplier, qty, price])

Now let's say you want to get the lead times for all suppliers and filter your prices to be no more than 30 days old:


Response

The response from the search is a dictionary containing all the requested part numbers as keys.

Each key contains another dictionary with the keys found and data and have the following format:

{
  "PN#": {
    "found" : True / False,
    "data" : {...}
  },
  {...}
}

The default query response has the following format:

part {
      mpn
      manufacturer {
        name
      }
      shortDescription
      specs {
        attribute {
          name
          group
        }
        displayValue
      }
      octopartUrl
      similarParts {
        mpn
        shortDescription
        manufacturer {
          name
        }
        octopartUrl
        category {
          name
        }
      }
      companionProducts {
        part {
          mpn
          shortDescription
          manufacturer {
            name
          }
          octopartUrl
          category {
            name
          }
        }
      }
      category {
        name
      }
      bestDatasheet {
        url
      }
      counts
      medianPrice1000 {
        price
      }
      sellers {
        company {
          name
        }
        country
        offers {
          sku
          inventoryLevel
          moq
          prices {
            quantity
            price
            currency
          }
          clickUrl
          updated
          factoryLeadDays
        }
        isRfq
      }
    }

You can change the query response by using the method changeQuery():

newResponse = 
'''
query Search($mpn: String!) {
    supSearchMpn(q: $mpn, limit: 1) {
      results {
        part {
            mpn
            shortDescription
            manufacturer {
              name
            }
        }
      }
    }
}
'''

search.changeQuery(newResponse)

API Part Reference

https://octopart.com/api/v4/reference#part

License

GNU LGPL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsg_parts_search-0.0.4.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nsg_parts_search-0.0.4-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file nsg_parts_search-0.0.4.tar.gz.

File metadata

  • Download URL: nsg_parts_search-0.0.4.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.10 Windows/10

File hashes

Hashes for nsg_parts_search-0.0.4.tar.gz
Algorithm Hash digest
SHA256 67bfe7b4934dff6d3adc253aae9f6706eefa4bb674019b99e0c632ece927a078
MD5 d13f2610164d54d71b2e1df8935da174
BLAKE2b-256 54662ee2bc4d8434e36dce8270d87ddff3e0510ce85ab9a0cea417f5ead0c104

See more details on using hashes here.

File details

Details for the file nsg_parts_search-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: nsg_parts_search-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.10 Windows/10

File hashes

Hashes for nsg_parts_search-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6702bbc7fe85e69addd9144c69757b2ed4fc2e965e40872c666ac20cb962f661
MD5 feb18c776b972061a26d6ade393feaed
BLAKE2b-256 ff884fb073746fdd71ab658a05eb05f3d2b1b8ceef29a463df1776b4e82395f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page