1

I'm writing a python library to interface to a rest server. I would like to be able to add classes inside the library, which I would like to be hidden once the library is installed via pip and imported into any project.

Example of the library structure:

.
├── my_library
    ├── __init__.py
    ├── controller
    |   ├──OtherClass.py
    |   └──Client.py
    └── models
        ├── __init__.py
        └── MyModel.py

Content of __init__.py in root folder.

from .controller.Client import Client

setup.py:

from setuptools import find_packages, setup

setup(
    name='my_library',
    packages=find_packages(include=['my_library']),
    version='0.1.0',
    description='My library',
    author='Pasini Matteo',
    setup_requires=['pytest-runner'],
    license='MIT',
    tests_require=['pytest==4.4.1'],
    test_suite='tests',
)

what I would like not to be able to do those who use the library:

from my_library.controller.OtherClass import OtherClass

python version >= 3.6

Matteo Pasini
  • 1,787
  • 3
  • 13
  • 26
  • 2
    Does this answer your question? ["Private" (implementation) class in Python](https://stackoverflow.com/questions/551038/private-implementation-class-in-python) – Xiddoc Dec 21 '22 at 15:28
  • 1
    Does this answer your question? [Python: 'Private' module in a package](https://stackoverflow.com/questions/3602110/python-private-module-in-a-package) TLDR: Python doesn't really have "true" private modules/classes/attributes. It's common practice to indicate privacy with leading underscores. – Axe319 Dec 21 '22 at 15:30

0 Answers0