Package: collections-extension
Some extra python data containers (extra collections).This project extends python`s core librarycollectionsmodule.Getting started.Installation.We have no pypi account yet and we have no private pypi repository.
So, you should install this package as usual withpippackage manager in
virtualenv or just globally from source:pipinstallgit+https://bitbucket.org/bfg-soft/collections_extension.gitIf you want to install specific version or branch, you should execute:pipinstallgit+https://bitbucket.org/bfg-soft/collections_extension.git@v0.1.0Content.Native-like containers.As we know, it is not recommended to inherit your own types from python`s
core types likedictortuple.
This package provides some native-like types, such as:Tuple-tuple-like container for user types (immutable),List-list-like container for user types (mutable),Dict-dict-like container for user types (mutable),Map-MappingProxyType-like (dictwithout mutability) container for user
types (immutable),Set-set-like container for user types (mutable)Exception map container.Container implements map of exception classes with inheritance check during
searching key in map. For example, we haveExceptionMap:fromcollections_extensionimportExceptionMapm=ExceptionMap({ValueError:'somevalue'})Imagine, that we catchUnicodeErrorsomewere in program and we want to
process it. Our processing is based on definedExceptionMapmand we
want to know what value we should send futher to the program runtime.fromcollections_extensionimportExceptionMapm=ExceptionMap({ValueError:'somevalue'})...defsomefn():try:...exceptUnicodeError:value=m[UnicodeError]exceptTypeError:value=m.get(TypeError)ifvalueisNone:raiseelse:value=NonereturnvalueExceptionMapwill search the hierarchy of key exception until it comes toExceptionclass. Only after that, map will raiseKeyErrorexception.Our map doesn`t containUnicodeErrorkey, but it containsValueError. We know, thatUnicodeErrorinheritsValueErrorexception class, sovalueduring handlingUnicodeErrorwill be
assigned tosomevaluestring.During handling ofTypeErrorexception we use methodgetofExceptionMap. It doesn`t raise any exception, like method of typedictand returns default value (second argument, that should be passing to
the method) orNone.Becides that,ExceptionMapallow to defineddefault_valueduring it`s
initialization like:fromcollections_extensionimportExceptionMapm=ExceptionMap({ValueError:'somevalue'},default_value='not none')It overrides default valueNone, that will be returned when key does not
exist and not default value has been passed.Sqlalchemy declarative model map container.Container implements map ofsqlalchemydeclarative
meta classes as values and their tablenames as keys.For example, you have moduleyour_package.data.modelwith sqlalchemy
declarative models.You can make map of declarative models withthis code:fromcollections_extensionimportSqlalchemyModelMapMODEL_MAP=SqlalchemyModelMap.from_module_name('your_package.data.model')After that, you can find all declarative model classes in this map (if your
structured module correctly) by their tablename. For exampleMODEL_MAP['my_table']will get you declarative model formy_tabletable.Sqlalchemy declarative model schema map container.Container implements map ofmarshmallowschema
instances as values and tablenames of declarative model classes as keys.Each marshmallow schema creates with special librarymarshmallow-sqlalchemy,
which inspects declarative model classes and makes schema class as a result.Typical usage:fromcollections_extensionimportSqlalchemyModelMap,SqlalchemyModelSchemaMapMODEL_MAP=SqlalchemyModelMap.from_module_name('your_package.data.model')MODEL_SCHEMA_MAP=SqlalchemyModelSchemaMap.from_sqlalchemy_model_map(MODEL_MAP)License.This project is licensed under the MIT License - see theLICENSE.txtfile for details.