Skip to content

Expose core functionality through __all__ in __init__.py #99

@julianstirling

Description

@julianstirling

labthings-fastapi is a reasonably large library divided into many different files. This however means that using labthings-fastapi tends to include mega import blocks like:

Image

This is has a few issues:

  • Imports get large and scary
  • In the rest of the code it is not clear what functions come directly from labthings-fastapi without going looking
  • Anyone using labthings-fastapi but lookup/remember the file structure to get to commonly used functionality
  • If labthings-fastapi changes its internal structure, the public API changes too

In contrast:

import numpy as np

is very clean, exposes a huge amount of functionality, and all of that functionality is clearly from NumPy as each command starts with np.

Proposal

Pick the most core functionality and expose it with __all__ from __init__.py. So that it is possible to import with the line

import labthings-fastapi as lt

This should allow the user to access:

  • lt.Thing
  • lt.thing_action
  • lt.thing_property
  • lt.GetThingStates
  • lt.BlockingPortal
  • lt.BlockingPortal
  • lt.direct_thing_client_dependency
  • lt.raw_thing_dependency
  • lt.InvocationLogger
  • lt.MJPEGStreamDescriptor
  • lt.Blob
  • lt.NDArray

This would simplify the examples as for some of the examples the import lines are about 40% of the examples. Also if this syntax is used in testing it will make it clear whether the public API has changed when reorganising the underlying file structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions