1

I have following structure:

/api
    /v0
        api_1.py
        api_2.py
    /v1
        api_1.py
        api_2.py

I would like to use it like that:

import api

api.v0.api_1.notify_user('1337')

However when I do for example dir(api.v0.api_1), I will get not only the API methods but all the imports that are performed inside. I feel other developers should not be bothered of what I use internally.

One of the solutions I am considering is to change all internal imports in api_1 to something like that:

import collections as _collections

to clearly indicate it's not a part of a public API. However, this seems to be very strange.

How should I solve this puzzle? Or maybe I should not bother at all and what I am trying to achieve is an overkill?

2

1 Answer 1

4

Probably you need to import public stuff in __init__.py. File structure should look so:

/api
    /v0
       __init__.py # import public stuff here
       api_1.py
       api_2.py
    /v1
       __init__.py
       api_1.py
       api_2.py

In the code:

api.v0.notify_user('1337')
Sign up to request clarification or add additional context in comments.

1 Comment

That is the thing I end up using.

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.