Reputation: 406
I am really new to python packaging. It already is a confusing topic with recommended ways and options that only a minority seems to apply. But to make it worse, I stumbled over this problem.
I started with the intention to write a rather small package with a really focussed purpose. My first solution included import of pandas. But I got the request to remove that dependency. So I tried to refactor the function and unsurprisingly it's slower. And slower to an extent that I can't hardly accept it.
So a solution would be to provide a package that uses pandas and a package that don't uses pandas. So that people can use either or, depending on project requirements. Now I am wondering what the best way is to provide that.
I could:
What is a good way to fulfill the different needs?
Upvotes: 0
Views: 667
Reputation: 492
I think optional dependencies are a pretty good use case for this.
You could define an optional dependecy named your_package[fast]
that installs pandas.
And in your code you could try something like:
try:
import pandas as pd
PANDAS_INSTALLED = True
except ImportError:
PANDAS_INSTALLED = False
# some other code...
if PANDAS_INSTALLED:
def your_function(...): # pandas installed
...
else:
def your_function(...): # pandas not installed
...
Upvotes: 2