naive packaging question

Discussion in 'Python' started by Scott Sharkey, Mar 26, 2008.

  1. Hello all,

    I've read a number of the python books, and several online tutorials
    about modules and packaging, but not one addresses this issue, so I
    thought I'd ask here...

    I am building a library for use in an internal project. This library
    is the client side interface to a REST-ful service that provides
    access to parts of our accounting database. BUT, we are pretty sure
    that the accounting database and hence the service implementation will
    change in the future.

    So, I want to design a generic (abstract) api for fetching various info
    from the accounting db, but I want to isolate the specific details into
    a module/package that can be changed in future (and co-exist with the
    old one).

    I've designed a generic api class, with functions to fetch the various
    info into python data structures (mostly lists of dictionaries, some
    just single values). And I've got an interface-specific version that
    follows that same api, and which is derived from the generic api.

    I'm a bit unclear on the best way to implement the module and package.

    Here's the directory structure that I've got so far:

    project <dir> top level directory
    setup.py
    company <dir> eventually, we'll have other modules
    __init__.py
    error.py some classes that will be used in all
    log.py modules
    acctdb <dir> the acct db interface directory
    __init__.py
    api.py the abstract class def (derived from object)
    specific.py the specific implementation, derived
    from the api base class

    For arguments sake, let's call the base class (defined in api.py)
    'BaseClass', and the specific implementation 'SpecificClass(BaseClass)'

    So, in the acctdb/__init__.py, do I do something like this:

    if SPECIFIC_CLASS:
    from company.acctdb.specific import SpecificClass as BaseClass

    with the idea that at some point in the future I'd designate a
    different class in some other way?

    Hopefully this is enough info for you to see what I'm trying to
    accomplish. It's a bit like the DB interfaces, where there is
    a generic DB API, and then the different drivers to implement
    that API (MySQL, etc).

    Thanks for any suggestions!

    -scott
    Scott Sharkey, Mar 26, 2008
    #1
    1. Advertising

  2. Scott Sharkey

    Carl Banks Guest

    On Mar 26, 12:33 pm, Scott Sharkey <>
    wrote:
    > Here's the directory structure that I've got so far:
    >
    > project <dir> top level directory
    > setup.py
    > company <dir> eventually, we'll have other modules
    > __init__.py
    > error.py some classes that will be used in all
    > log.py modules
    > acctdb <dir> the acct db interface directory
    > __init__.py
    > api.py the abstract class def (derived from object)
    > specific.py the specific implementation, derived
    > from the api base class
    >
    > For arguments sake, let's call the base class (defined in api.py)
    > 'BaseClass', and the specific implementation 'SpecificClass(BaseClass)'
    >
    > So, in the acctdb/__init__.py, do I do something like this:
    >
    > if SPECIFIC_CLASS:
    > from company.acctdb.specific import SpecificClass as BaseClass



    Seems pretty reasonable to me. Do you have any specific reasons for
    being concerned about this organization?

    (My only minor suggestion would be not to import the SpecificClass as
    BaseClass, but instead with a name that's different from both, for
    example, PublicClass. All that does is to avoid a tiny bit of
    potential confusion down the road.)


    Carl Banks
    Carl Banks, Mar 26, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2Q=?=

    Naive question: Crystal reports in ASP.NET

    =?Utf-8?B?a2Q=?=, May 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    402
    Peter van der Goes
    May 28, 2005
  2. Frederic

    naive operator new question

    Frederic, Jul 3, 2003, in forum: C++
    Replies:
    0
    Views:
    308
    Frederic
    Jul 3, 2003
  3. Newsgroup - Ann
    Replies:
    1
    Views:
    2,087
    Davlet Panech
    Oct 29, 2003
  4. Gabriel B.

    naive doc question

    Gabriel B., Jan 30, 2005, in forum: Python
    Replies:
    2
    Views:
    276
    Duncan Booth
    Jan 30, 2005
  5. naive size of array question

    , Nov 21, 2005, in forum: C Programming
    Replies:
    7
    Views:
    304
    Mike Wahler
    Nov 21, 2005
Loading...

Share This Page