Pythonic API design
<p>My objective is to design a Python API that allows clients to do the following:</p>

<pre><code>md = MentalDisorders()
print(md.disorders['eating'])
</code></pre>

<p>to get a list of eating-related disorders.</p>

<p>Here is my stab at it, consider that FAKE_DATABASE will be a real database and I am just focussing this question on the "feel"/"usability" of the interface, especially in a Python context, to which I am alien:</p>

<pre><code>#!/usr/bin/env python2.7

FAKE_DATABASE = {
  'anxiety': ['phobia', 'panic'],
  'personality': ['borderline', 'histrionic'],
  'eating': ['bulimia', 'anorexia'],
}

class MentalDisorders(object):
  # ... some methods and fields that make it worthwhile having a container class ...
  class DisorderCollection(object):
    def __getitem__(self, key):
      if key in FAKE_DATABASE:
        return FAKE_DATABASE[key]
      else:
        raise KeyError('Key not found: {}.'.format(key))
  def __init__(self):
    self.disorders = self.DisorderCollection()

def main():
  md = MentalDisorders()
  print(md.disorders['anxiety'])
  print(md.disorders['personality'])
  print(md.disorders['eating'])
  try:
    print(md.disorders['conduct'])
  except KeyError as exception:
    print(exception)

if __name__ == '__main__':
  main()
</code></pre>

<ol>
<li>Is having a <code>DisorderCollection</code> advisable at all?</li>
<li>Should <code>DisorderCollection</code> be defined within <code>MentalDisorders</code> or outside of it?</li>
<li>Is instantiating <code>self.disorders</code> via <code>self.DisorderCollection</code> correct?</li>
<li>Should instantiation of a <code>DisorderCollection</code> to be used as a field happen from
within the <code>__init__</code> method of <code>MentalDisorders</code>?</li>
<li>Should perhaps no field instance of <code>DisorderCollection</code> exist at all and the above
be implemented as a simple "forwarding call" from <code>__getattribute__</code> to a key
look-up in the database? What would a simple <code>md.disorders</code> (with no key specified)
return in that case?</li>
</ol>
