I've set up my sqlalchemy table definitions in different modules all within a folder named schemas
. For example:
ls -1 schemas/*.py $
schemas/__init__.py
schemas/base.py
schemas/reference.py
schemas/warehouse.py
However, to now use these definitions in a reflective manner by looking at the base._decl_class_registry
or base.metadata
I need to import the schema modules:
from schemas import base, reference, warehouse, reference
This then causes an unused import
warning because I'm not directly referencing the table definitions within those modules and instead pulling out information from the base.
It seems that the issue is sqlalchemy registering these tables by simply doing an import.
I've looked through sqlalchemy documentation and can't quite find out if it's possible to do this registration in some more pythonic way.
Here's an example of what I'm effectively doing.
# removing this means reference is no longer registered to the metadata
from schemas import base, reference
class SomeOtherClass:
def printMetadata():
print(base.Base.metadata)
Is there a better way to import these modules and tables?
I'm hoping to be able to do this without the flake8 warning to conform to my code styling.