Counter object in Python with public and private methods I am trying to implement an open source desktop application with python. I want to provide both a gui and an API. I know there is no private methods in python but i am trying to find the most elegant way to keep some methods private. I do not want my users to see all list of methods while using API. After some research, I come up with the implementation below and wondering if there is any problem with my implementation of this concept and if there is any room for improvement. Please provide me a review and do not hesitate to ask any questions you have. Here is my try:

from pprint import pprint


# CamelCase because it "acts" like a class
def CounterController():
    class CounterControllerPrivate(object):
        def __init__(self):
            self.counter = 0

        def add_one(self):
            self.counter += 1

        def reset(self):
            self.counter = 0

        def get_counter(self):
            return self.counter

    counter_controller = CounterControllerPrivate()

    class CounterControllerPublic(object):
        def add_one_endpoint(self):
            counter_controller.add_one()
            return counter_controller.get_counter()

        def reset_endpoint(self):
            counter_controller.reset()
            return counter_controller.get_counter()

    return CounterControllerPublic()


# counter attribute is not accessible from out here
controller = CounterController()

print(controller.add_one_endpoint())
print(controller.add_one_endpoint())
print(controller.reset_endpoint())

pprint(dir(controller))
The private objects and attributes are easily accessed using inspect.getclosurevars:

&gt;&gt;&gt; c = CounterController()
&gt;&gt;&gt; import inspect
&gt;&gt;&gt; inspect.getclosurevars(c.add_one_endpoint)
ClosureVars(nonlocals={'counter_controller': &lt;__main__.CounterController.&lt;locals&gt;.CounterControllerPrivate object at 0x10a047cf8&gt;}, globals={}, builtins={}, unbound={'add_one'})
&gt;&gt;&gt; _.nonlocals['counter_controller']
&lt;__main__.CounterController.&lt;locals&gt;.CounterControllerPrivate object at 0x10a047cf8&gt;
&gt;&gt;&gt; _.counter
0


So you might consider whether it's worth spending a lot of effort on this approach. Personally I would spend the effort on API documentation instead.