Package: yamlalchemy
YAMLAlchemyYAMLAlchemy is a Python-based library to convert YAML string to SQLAlchemy read-only queries.InstallationInstallation via PyPI:pipinstallyamlalchemyUsagefromyamlalchemyimportparsefromsqlalchemy.engineimportURLfromsqlalchemyimportcreate_enginefromsqlalchemy.ormimportSessionfromsqlalchemy.ext.automapimportautomap_baseimportpandasaspduri=URL.create(**{'drivername':"mysql+pymysql","username":"guest","host":"relational.fit.cvut.cz","port":"3306","password":"relational","database":"AdventureWorks2014"})engine=create_engine(uri)engine.connect()base=automap_base()yaml_content="""$from: Product$column:-$name: Color$alias: Color of Product-$name: ListPrice$alias: List Price of Product$func: avg$where:-$name: Color$filter:$nis: null-$name: SellStartDate$filter:$gt: 2013-01-01$group:-$name: Color$order:-$name: Name$direction: asc$limit: 10$offset: 0"""engine=get_engine()base.prepare(engine,reflect=True)session=Session(engine)qs=parse(yaml_content,session,base).to_query()df=pd.read_sql_query(qs.statement,session.connection())YAML Query Language SyntaxDescriptionFROMName of the table from which to select data. For now, YAMLAlchemy supports only one table.IdentifierData Type$columnStringUsage:$from:ProductCOLUMNSField names of the table you want to select data from.IdentifierData Type$columnListColumn Definition:IdentifierDescriptionRequired$nameName of columnTrue$aliasAlias of columnFalse$funcAggregate function of column. avg, sum, etc...FalseUsage:$column:-$name:Color$alias:Color of Product-$name:ListPrice$alias:List Price of Product$func:avgGROUPField names of the table you want to group the same values into summary rows.IdentifierData Type$groupListColumn Definition:IdentifierDescriptionRequired$nameName of columnTrueUsage:$group:-$name:ColorORDERField names of the table you want to sort result-set in ascending or descending order.IdentifierData Type$orderListColumn Definition:IdentifierDescriptionRequiredDefaults$nameName of columnTrue--$directionAscending or descending orderFaseascordescUsage:$order:-$name:Name$direction:ascWHEREFiltering records  to return.IdentifierData Type$whereListColumn Definition:IdentifierDescriptionRequired$nameName of columnTrue$filterList of filter definitionsTrueFilter Definition:Filtering consists of the following two parts.Operator Definition:This part is optional.IdentifierDescription$andCombines where statements withAND$orCombines where statements withOR$notCombines where statements withNOTComparator Definition:This part is required.IdentifierDescriptionSQL Part (MySQL)$eqEqualCOLUMN = 'value'$gtGreator thanCOLUMN > 'value'$gteGreater than or equalCOLUMN >= 'value'$ltLess thanCOLUMN > 'value'$lteLess than or equalCOLUMN <= 'value'$neqNot equalCOLUMN != 'value'$likeLikeCOLUMN LIKE '%value%'$ilikeCase-insensitive likeCOLUMN ILIKE '%value%'$nlikeNot likeCOLUMN NOT LIKE '%value%'$nilikeCase-insensitive not likeCOLUMN NOT ILIKE '%value%'$inInCOLUMN IN ['value1', 'value2]$ninNot inCOLUMN NOT IN ['value1', 'value2]$is (:null)is nullCOLUMN IS NULL$nis (:null)Is not nullCOLUMN IS NOT NULL$containsContains (Operand should contain 1 column)COLUMN LIKE '%value%'$startswithStarts withCOLUMN LIKE 'value%'$endswithEnds withCOLUMN LIKE '%value'Usage:$where:-$name:Class$filter:$is:null-$name:Color$filter:$nis:null-$name:SellStartDate$filter:$gt:2013-01-01-$name:Style$filter:$or:$startswith:-U-MHAVINGFiltering with aggregate functions.IdentifierData Type$havingListColumn Definition:IdentifierDescriptionRequired$nameName of columnTrue$funcAggregate function nameTrue$filterFiltering part. Same sytntax with the filter part of WHERE statement.TrueUsage:$having:-$name:Review$func:avg$filter:$and:$lt:1500$gt:1000-$name:Stars$func:count$filter:$lt:20LIMITSpecifying the number of records to return.IdentifierData Type$limitIntegerUsage:$limit:10OFFSETSpecifying an offset from where to start returning data.IdentifierData Type$offsetIntegerUsage:$offset:10Running testspython-munittesttests/test_parser.pyRoadmapJoinsSub QueriesLicenseMIT LicenseCopyright (c) 2021 Ahmet ÖnolPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.