Giter Club home page Giter Club logo

pyoctopart's Introduction

pyoctopart

A simple Python client frontend to the Octopart public REST API.

For detailed API documentation, refer to the Octopart APIv2 documentation

This is a fork of Joe Baker's work, and this fork is incompatible with Python 2 distributions!

You'll find the sources of this project over https://github.com/guyzmo/pyoctopart

Usage

Install

just do:

python3 setup.py install

and it'll be available from your python REPL:

% python3
>>> from pyoctopart.octopart import Octopart
>>> o = Octopart.api(apikey="yourapikey")

when the lib will be considered stable enough, I'll upload it to pipy:

% pip install pyoctopart

Develop

if you just want to develop, you can do:

% buildout

which will download dependencies and deploy a python command in bin/:

% bin/python3
>>> from pyoctopart.octopart import Octopart
>>> o = Octopart.api(apikey="yourapikey")

You can run regression tests using:

% bin/test

Notes

API v3 conversion

At the time being only three methods have been switched to the new API:

parts_search()
parts_match()
parts_get()

And the tests will need to be updated. Those methods are the only one being used in the pyparts project, though.

method/argument syntax (for API v3)

A number of arguments in the v3 API are using syntax that are not compatible with python's syntax, such as include[]=datasheets. To enforce argument's type checking and stay compatible with the API, the arguments are converted as booleans replacing the assignment with an underscore, making it include_datasheets, so for the Part model you have the following matches:

includes

    include_short_description     → include[]=short_description
    include_datasheets            → include[]=datasheets
    include_compliance_documents  → include[]=compliante_documents
    include_descriptions          → include[]=descriptions
    include_imagesets             → include[]=imagesets
    include_specs                 → include[]=specs
    include_category_uids         → include[]=category_uids
    include_external_links        → include[]=external_links
    include_reference_designs     → include[]=reference_designs
    include_cad_models            → include[]=cad_models

Shows

    show_uid                      → show[]=uid
    show_mpn                      → show[]=mpn
    show_manufacturer             → show[]=manufacturer
    show_brand                    → show[]=brand
    show_octopart_url             → show[]=octopart_url
    show_offers                   → show[]=offers
    show_broker_listings          → show[]=broker_listings
    show_short_description        → show[]=short_description
    show_datasheets               → show[]=datasheets
    show_compliance_documents     → show[]=compliante_documents
    show_descriptions             → show[]=descriptions
    show_imagesets                → show[]=imagesets
    show_specs                    → show[]=specs
    show_category_uids            → show[]=category_uids
    show_external_links           → show[]=external_links
    show_reference_designs        → show[]=reference_designs
    show_cad_models               → show[]=cad_models

Hides

    hide_uid                      → hide[]=uid
    hide_mpn                      → hide[]=mpn
    hide_manufacturer             → hide[]=manufacturer
    hide_brand                    → hide[]=brand
    hide_octopart_url             → hide[]=octopart_url
    hide_offers                   → hide[]=offers
    hide_broker_listings          → hide[]=broker_listings
    hide_short_description        → hide[]=short_description
    hide_datasheets               → hide[]=datasheets
    hide_compliance_documents     → hide[]=compliante_documents
    hide_descriptions             → hide[]=descriptions
    hide_imagesets                → hide[]=imagesets
    hide_specs                    → hide[]=specs
    hide_category_uids            → hide[]=category_uids
    hide_external_links           → hide[]=external_links
    hide_reference_designs        → hide[]=reference_designs
    hide_cad_models               → hide[]=cad_models

As a reference, check the include/show/hide directives sections of the manual.

method/argument syntax (for API v2)

There are a number of arguments in the Octopart API documentation which contain periods in their names. When passing these arguments from Python, substitute an underscore for any periods.

Similarly, substitute underscores for backslashes in method names.

For example:

>>> o = Octopart()
>>> o.parts_get(1881614252472, optimize.hide_datasheets=True)
SyntaxError: keyword can't be an expression

Instead, pass the argument as:
>>> o.parts_get(1881614252472, optimize_hide_datasheets=True)

The library will perform the translation internally.

Roadmap

  • switch to python 3
  • create buildout build
  • use function annotations
  • [o] switch to v3 API
  • improve and fix tests

Authors

  • Forked by Bernard Guyzmo Pratz
  • Originally authored by Joe Baker

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

pyoctopart's People

Contributors

guyzmo avatar jbaker0428 avatar kaidokert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyoctopart's Issues

PyPI package doesn't successfully pip install due to missing README.md

I was trying to install pyoctopart from PyPI and ran into an issue:

(ve) [adrake@duality octopart]$ pip install pyoctopart
Collecting pyoctopart
  Using cached pyoctopart-0.6.3.tar.gz
    Complete output from command python setup.py egg_info:

    Installed /tmp/pip-build-v898zrde/pyoctopart/.eggs/setuptools_markdown-0.2-py3.4.egg
    Searching for pypandoc
    Reading https://pypi.python.org/simple/pypandoc/
    Best match: pypandoc 1.1.3
    Downloading https://pypi.python.org/packages/source/p/pypandoc/pypandoc-1.1.3.zip#md5=771f376bf9c936a90159cd94235998c2
    Processing pypandoc-1.1.3.zip
    Writing /tmp/easy_install-rwxxk5jg/pypandoc-1.1.3/setup.cfg
    Running pypandoc-1.1.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-rwxxk5jg/pypandoc-1.1.3/egg-dist-tmp-oqygmjv_
    zip_safe flag not set; analyzing archive contents...
    pypandoc.__pycache__.__init__.cpython-34: module references __file__
    Patching wheel building...
    creating /tmp/pip-build-v898zrde/pyoctopart/.eggs/pypandoc-1.1.3-py3.4.egg
    Extracting pypandoc-1.1.3-py3.4.egg to /tmp/pip-build-v898zrde/pyoctopart/.eggs

    Installed /tmp/pip-build-v898zrde/pyoctopart/.eggs/pypandoc-1.1.3-py3.4.egg
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-v898zrde/pyoctopart/setup.py", line 28, in <module>
        'setuptools',
      File "/usr/lib64/python3.4/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/home/adrake/src/octopart/ve/lib64/python3.4/site-packages/setuptools/dist.py", line 272, in __init__
        _Distribution.__init__(self,attrs)
      File "/usr/lib64/python3.4/distutils/dist.py", line 280, in __init__
        self.finalize_options()
      File "/home/adrake/src/octopart/ve/lib64/python3.4/site-packages/setuptools/dist.py", line 327, in finalize_options
        ep.load()(self, ep.name, value)
      File "/tmp/pip-build-v898zrde/pyoctopart/.eggs/setuptools_markdown-0.2-py3.4.egg/setuptools_markdown.py", line 22, in long_description_markdown_filename
        output = pypandoc.convert(markdown_filename, 'rst')
      File "/tmp/pip-build-v898zrde/pyoctopart/.eggs/pypandoc-1.1.3-py3.4.egg/pypandoc/__init__.py", line 50, in convert
        outputfile=outputfile, filters=filters)
      File "/tmp/pip-build-v898zrde/pyoctopart/.eggs/pypandoc-1.1.3-py3.4.egg/pypandoc/__init__.py", line 68, in _convert
        raise RuntimeError('Missing format!')
    RuntimeError: Missing format!

What's going on here is that the pypandoc-0.6.3.tar.gz distribution is missing a README.md file, and setuptools-markdown is attempting to build it with pypandoc and failing. If you add an empty README.md to the tarball, setup.py never tries to pull in pypandoc and the installation succeeds without incident.

This issue only occurs in the PyPI package, since the git repo contains a README.md. The easiest fix would be to upload a new version to PyPI containing that file.

On a side note - the version in PyPI is 0.6.3 and the version in git is 0.6.2 -- is there another repo somewhere with the most up to date code?

Example does not work

Hi,
the example of the main page does not work.

import pyoctopart.octopart
print(pyoctopart.octopart.__version__)
from pyoctopart.octopart import Octopart
o = Octopart.api(apikey="...")

I get 0.6.3 and the error: AttributeError: type object 'Octopart' has no attribute 'api'
dir(Octopart) gives me:
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_get_data', 'api_url', 'apikey', 'bom_match', 'callback', 'partattributes_get', 'partattributes_get_multi', 'parts_get', 'parts_match', 'parts_match_v2', 'parts_search', 'parts_suggest_v2', 'pretty_print', 'verbose']

Could you provide me with a working example please?

Thank you and kind regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.