Checklist for Python libraries APIs
python.apichecklist.com
python.apichecklist.com
Avoid hiding parameters that could be useful E.g. the API is calling another lower-level one, but it isn't exposing some useful parameters the lower-level API supports
APIs have to be supported for years. Anything they expose can become a serious hindrance for API migration in the future. Best to keep the API as simple as possible at first, then only expand it when it is genuinely necessary.
Another one I would add: Keep the API stable. I'm developing a cross-platform file manager with a Python API [1]. I made some (necessary) changes to the API last week. This broke the work flows of some of my users. They were not pleased.
[1]: https://fman.io
One way to avoid that is to pass down kwargs to the low-level call. `pandas` uses that in their plotting function (passed down the matplotlib call).
And in python, if they really need more they can monkeypatch the world.
You don't need to expose each internal parameter or write adapters to everything you use. As suggested by the sibling here, sometimes all you need is to pass down kwargs to the low-level call.
Other API guidelines that suggest a similar approach here:
http://tomasp.net/blog/2015/library-layers/
http://www.thereformedprogrammer.net/what-makes-a-good-softw...
I'm also skeptical to all the recommendations about opening up the internals, getting out of the abstractions and providing replaceable hooks for everything. This can create premature abstractions for every conceivable hook and exposing internals will give you a backwards compatibility maintenance hell when you have to be compatible with internal details you didn't think people depended on.
When you look at their example import code it makes even less sense. People who need shorter object names already do that, no need for it to be at the library level.
It was dumb. I won't do it again.
I think if you do it early on you are stuck though. If beautiful soup changes now they will break a ton of code.
Using Keras has made me appreciate this a lot.
Most deep learning layers have a bunch of parameters that need to be configured for best results. A lot of research has gone into figuring out best practices and Keras uses those as defaults. Saves me a lot of time.
Honestly I couldn’t care less about PEP8... frankly my flake tool triggers a build failure more often than an actual code problem. This list, however, should be used like a golden rule for python software development (and all software, regardless of language) – a lot of these principles are universal.
https://github.com/vintasoftware/python-api-checklist/blob/m...