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:

import nsgsearch

# 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

You can filter your results like this:


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.2.tar.gz (14.9 kB view hashes)

Uploaded Source

Built Distribution

nsg_parts_search-0.0.2-py3-none-any.whl (15.0 kB view hashes)

Uploaded Python 3

Supported by

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