2

I have created a sdk which makes use of multiple dependencies for example boto3, azure-storage, google-cloud-datastore etc. Now in my code I am importing these modules dynamically because at a time user will be using the sdk on GCP, Azure or AWS. So I do not want to install dependencies which he'll not be using. Here's my questions -

  1. Is my approach correct, should I install all the dependencies?

  2. If not then what's best way to install the package so that user can provide some argument to the package manager so that it installs only those dependencies which belongs to the environment he is on.

    Something like pip install mysdk --env=aws

P.S. I got to know that python does support install_requires parameter in setup.py where python_version variable can be used but can I access other env variables defined by user as args

1 Answer 1

2

You can define optional dependencies in your setup.py (or setup.cfg) in the extras_require block.

In the case of your setup.py file

setup(
    ...
    extras_require={
        'aws':  ["boto3"],
    }
)

or for a setup.cfg file

[options.extras_require]
aws = 
    boto3

When the end-user installs your package they can specify extras by appending them with: pip install mysdk[aws]

Note that you can also specify version ranges of dependant packages just like any other dependency.

For more information, the related documentation is here: https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies

Sign up to request clarification or add additional context in comments.

2 Comments

So can a developer who is using the sdk specify mysdk[aws]==1.0.0 in his requirements.txt file?
@himanshu219 that is correct. Although I would recommend using mysdk[aws] >=1.0,<2.0 or use pipenv with mysdk[aws] ~= 1.0. So they get bug fixes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.