gensaschema package¶
Submodules¶
- gensaschema._column module
- gensaschema._config module
- gensaschema._constraint module
- Constraint inspection and representation
Constraint
Constraint.constraint
Constraint._IMPORT
Constraint._SYMBOL
Constraint.__cmp__()
Constraint.__dict__
Constraint.__firstlineno__
Constraint.__init__()
Constraint.__lt__()
Constraint.__module__
Constraint.__new__()
Constraint.__static_attributes__
Constraint.__weakref__
Constraint.copy()
Constraint.repr()
ForeignKeyConstraint
PrimaryKeyConstraint
UniqueConstraint
access_col()
- gensaschema._exceptions module
- gensaschema._meta module
- gensaschema._schema module
- gensaschema._symbols module
- Symbol management
SymbolException
Symbols
Symbols._symbols
Symbols.imports
Symbols.types
Symbols.__annotations__
Symbols.__contains__()
Symbols.__delitem__()
Symbols.__dict__
Symbols.__firstlineno__
Symbols.__getitem__()
Symbols.__init__()
Symbols.__iter__()
Symbols.__module__
Symbols.__setitem__()
Symbols.__static_attributes__
Symbols.__weakref__
_Imports
_Types
_load_dotted()
- gensaschema._table module
- gensaschema._template module
- gensaschema._type module
- gensaschema._util module
- gensaschema.constraints module
Module contents¶
- Copyright:
Copyright 2010 - 2025 André Malo or his licensors, as applicable
- License:
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
GenSASchema - Static SQLAlchemy Schema Generator¶
GenSASchema generates static schema definitions using SQLAlchemy’s inspection capabilities.
- class gensaschema.Config(tables, schemas, lines=None)[source]¶
Schema config container
- tables¶
Table list
- Type:
list
- schemas¶
Alien schema mapping
- Type:
dict
- _lines¶
Original config lines (or
None
)- Type:
list
- _CONFIG_TPL = <gensaschema._template.Template object>¶
Template for empty config file
- Type:
Template
- __dict__ = mappingproxy({'__module__': 'gensaschema._config', '__firstlineno__': 46, '__doc__': '\nSchema config container\n\nAttributes:\n tables (list):\n Table list\n\n schemas (dict):\n Alien schema mapping\n\n _lines (list):\n Original config lines (or ``None``)\n', '_CONFIG_TPL': <gensaschema._template.Template object>, '__init__': <function Config.__init__>, 'from_file': <classmethod(<function Config.from_file>)>, 'from_lines': <classmethod(<function Config.from_lines>)>, 'from_parser': <classmethod(<function Config.from_parser>)>, 'dump': <function Config.dump>, '__static_attributes__': ('_lines', 'schemas', 'tables'), '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__annotations__': {}})¶
- __firstlineno__ = 46¶
- __init__(tables, schemas, lines=None)[source]¶
Initialization
- Parameters:
tables (
list
) – Table listschemas (
dict
) – (Alien) Schema mappinglines (
iterable
) – Original config lines. If omitted orNone
, the config lines are not available.
- __module__ = 'gensaschema._config'¶
- __static_attributes__ = ('_lines', 'schemas', 'tables')¶
- __weakref__¶
list of weak references to the object
- classmethod from_file(name_or_file)[source]¶
Construct from config file
- Parameters:
name_or_file (
str
orfile
) – Config filename or file pointer- Returns:
New Config instance
- Return type:
- Raises:
IOError – Error reading the file (except for ENOENT, which treats the file as empty)
- exception gensaschema.Error[source]¶
Base exception for this package
- __firstlineno__ = 34¶
- __module__ = 'gensaschema._exceptions'¶
- __static_attributes__ = ()¶
- __weakref__¶
list of weak references to the object
- class gensaschema.Schema(conn, tables, schemas, symbols, dbname=None, types=None)[source]¶
Schema container
- _dialect¶
Dialect name
- Type:
str
- _tables¶
Table collection
- Type:
TableCollection
- _schemas¶
Schema -> module mapping
- Type:
dict
- _symbols¶
Symbol table
- Type:
- _dbname¶
DB identifier
- Type:
str
orNone
- _MODULE_TPL = <gensaschema._template.Template object>¶
Template for the module
- Type:
Template
- __dict__ = mappingproxy({'__module__': 'gensaschema._schema', '__firstlineno__': 36, '__doc__': '\nSchema container\n\nAttributes:\n _dialect (str):\n Dialect name\n\n _tables (TableCollection):\n Table collection\n\n _schemas (dict):\n Schema -> module mapping\n\n _symbols (Symbols):\n Symbol table\n\n _dbname (str or None):\n DB identifier\n', '_MODULE_TPL': <gensaschema._template.Template object>, '__init__': <function Schema.__init__>, 'dump': <function Schema.dump>, '__static_attributes__': ('_dbname', '_dialect', '_schemas', '_symbols', '_tables'), '__dict__': <attribute '__dict__' of 'Schema' objects>, '__weakref__': <attribute '__weakref__' of 'Schema' objects>, '__annotations__': {}})¶
- __firstlineno__ = 36¶
- __init__(conn, tables, schemas, symbols, dbname=None, types=None)[source]¶
Initialization
- Parameters:
conn (
Connection
orEngine
) – SQLAlchemy connection or enginetables (
list
) – List of tables to reflect, (local name, table name) pairsschemas (
dict
) – schema -> module mappingsymbols (
gensaschema.Symbols
) – Symbol tabledbname (
str
) – Optional db identifier. Used for informational purposes. If omitted orNone
, the information just won’t be emitted.types (
callable
) – Extra type loader. If the type reflection fails, because SQLAlchemy cannot resolve it, the type loader will be called with the type name, (bound) metadata and the symbol table. It is responsible for modifying the symbols and imports and the dialect’sischema_names
. If omitted orNone
, the reflector will always fail on unknown types.
- __module__ = 'gensaschema._schema'¶
- __static_attributes__ = ('_dbname', '_dialect', '_schemas', '_symbols', '_tables')¶
- __weakref__¶
list of weak references to the object
- exception gensaschema.SymbolException[source]¶
Symbol error
- __annotations__ = {}¶
- __firstlineno__ = 39¶
- __module__ = 'gensaschema._symbols'¶
- __static_attributes__ = ()¶
- class gensaschema.Symbols(symbols=None, imports=None)[source]¶
Symbol table
- _symbols¶
Symbols
- Type:
dict
- imports¶
Import container
- Type:
_Imports
- types¶
Type container
- Type:
_Types
- __contains__(name)[source]¶
Check symbol table entry
- Parameters:
name (
str
) – Symbol identifier- Returns:
Does the symbol entry exist?
- Return type:
bool
- __delitem__(name)[source]¶
Remove symbol entry if available
- Parameters:
name (
str
) – Symbol identifier
- __dict__ = mappingproxy({'__module__': 'gensaschema._symbols', '__firstlineno__': 43, '__doc__': '\nSymbol table\n\nAttributes:\n _symbols (dict):\n Symbols\n\n imports (_Imports):\n Import container\n\n types (_Types):\n Type container\n', '__init__': <function Symbols.__init__>, '__delitem__': <function Symbols.__delitem__>, '__setitem__': <function Symbols.__setitem__>, '__getitem__': <function Symbols.__getitem__>, '__contains__': <function Symbols.__contains__>, '__iter__': <function Symbols.__iter__>, '__static_attributes__': ('_symbols', 'imports', 'types'), '__dict__': <attribute '__dict__' of 'Symbols' objects>, '__weakref__': <attribute '__weakref__' of 'Symbols' objects>, '__annotations__': {}})¶
- __firstlineno__ = 43¶
- __getitem__(name)[source]¶
Get symbol table entry
- Parameters:
name (
str
) – Symbol identifier- Returns:
The symbol
- Return type:
str
- Raises:
KeyError – Symbol not found
- __init__(symbols=None, imports=None)[source]¶
Initialization
- Parameters:
symbols (
dict
) – Initial symbolsimports (
iterable
) – List of initial (id, import statement) tuples. If omitted orNone
, it’s empty.
- __module__ = 'gensaschema._symbols'¶
- __setitem__(name, symbol)[source]¶
Set symbol table entry
- Parameters:
name (
str
) – Symbol identifiersymbol (
str
) – Symbol
- Raises:
SymbolException – Symbol could not be set because of some conflict
- __static_attributes__ = ('_symbols', 'imports', 'types')¶
- __weakref__¶
list of weak references to the object
- class gensaschema.Type(ctype, dialect_name, symbols)[source]¶
Type container
- _ctype¶
Column type
- Type:
SA type
- _dialect¶
Dialect name
- Type:
str
- _symbols¶
Symbol table
- Type:
- __dict__ = mappingproxy({'__module__': 'gensaschema._type', '__firstlineno__': 38, '__doc__': '\nType container\n\nAttributes:\n _ctype (SA type):\n Column type\n\n _dialect (str):\n Dialect name\n\n _symbols (Symbols):\n Symbol table\n', '__init__': <function Type.__init__>, 'by_column': <classmethod(<function Type.by_column>)>, '__repr__': <function Type.__repr__>, '__static_attributes__': ('_ctype', '_dialect', '_symbols'), '__dict__': <attribute '__dict__' of 'Type' objects>, '__weakref__': <attribute '__weakref__' of 'Type' objects>, '__annotations__': {}})¶
- __firstlineno__ = 38¶
- __init__(ctype, dialect_name, symbols)[source]¶
Initialization
- Parameters:
ctype (
SA type
) – Column typedialect_name (
str
) – Dialect namesymbols (
gensaschema.Symbols
) – Symbol table
- __module__ = 'gensaschema._type'¶
- __static_attributes__ = ('_ctype', '_dialect', '_symbols')¶
- __weakref__¶
list of weak references to the object
- exception gensaschema.Warning[source]¶
Base warning for this package
>>> with _warnings.catch_warnings(record=True) as record: ... _warnings.resetwarnings() ... Warning.emit('my message') >>> assert len(record) == 1 >>> str(record[0].message) 'my message'
>>> _warnings.simplefilter('error') >>> Warning.emit('lalala') Traceback (most recent call last): ... Warning: lalala
- __firstlineno__ = 38¶
- __module__ = 'gensaschema._exceptions'¶
- __static_attributes__ = ()¶
- __weakref__¶
list of weak references to the object
- classmethod emit(message, stacklevel=1)[source]¶
Emit a warning of this very category
This method is pure convenience. It saves you the unfriendly
warnings.warn
syntax (and thewarnings
import).- Parameters:
- messageany
The warning message
- stacklevel
int
Number of stackframes to go up in order to place the warning source. This is useful for generic warning-emitting helper functions. The stacklevel of this helper function is already taken into account.