Package: csvms
Comma-SeparatedValuesManagementSystemPython module to manageCSVdata like aDBMSapplication with educational purposesInstallationpipinstallcsvmsUsageThis is an simple example of use:fromcsvms.tableimportTable# Create tableA=Table(name="A",columns={"c1":int,"c2":str,"c3":float},data=[(1,"Hello",0.1),(2,"World",1.0),])# Insert one rowA.append(3,"Some",0.8)# Create a new table 'B' with extended 'A' result of (100 * c3) called c4, and then# select rows where c4 are greater then 50B=A.Π({'mul':[{'literal':100},'c3']},"c4").σ({"gt":['c4',50]})# Project columns c1, c2 and c4 and print tableprint(B.π(['c1','c2','c4']))the expected result will be like thisTABLE: default.(((AΠ)π)σ)
 +---+-----+-----+
 |c1 |c2   |c4   |
 +---+-----+-----+
0|  2|World|100.0|
1|  3| Some| 80.0|
 +---+-----+-----+TableTheTableobject represents a CSV data file.You can create asampletable likefromcsvms.tableimportTabletbl=Table(name="sample",columns={"c1":int,"c2":str,"c3":float},data=[(1,"Hello",0.1),(2,"World",1.0),])Without spefify a database onnamethis table will be created under a default directory ($CSVMS_DEFAULT_DB). Thecolumnsis a dictionary composed by the name and type usingpython primitive data typesand thedataneed to be a list of tuplesUsingprintyou can they see the object as a table representation>>>print(tbl)TABLE:default.sample+---+-----+---+|c1|c2|c3|+---+-----+---+0|1|Hello|0.1|1|2|World|1.0|+---+-----+---+thesavefunction will write all data in aCSVformat based on the tablelocationpropertytbl.save()catdata/default/sample.csv1;Hello;0.12;World;1.0For more informatios usehelp(Table)Data accessIt's possible to access a row by yourindexvalue, like a simple python tuple>>>tbl[1]{'c1':2,'c2':'World','c3':1.0}The row will be return as andictionary, so, with the column name (after the index) you can access the value associated>>>tbl[1]["c2"]'World'It's also possible iterate into all rows using aforloop>>>forrowintbl:...print(row)...(1,'Hello',0.1)(2,'World',1.0)Data manipulationYou can add a new row using theappendfunction>>>tbl.append(3,"Some",0)>>>print(tbl)TABLE:default.sample+---+-----+---+|c1|c2|c3|+---+-----+---+0|1|Hello|0.1|1|2|World|1.0|2|3|Some|0.0|+---+-----+---+Update a specific row by yourindex>>>tbl[0]=(4,"Value",3.3)>>>print(tbl)TABLE:default.sample+---+-----+---+|c1|c2|c3|+---+-----+---+0|4|Value|3.3|1|2|World|1.0|2|3|Some|0.0|+---+-----+---+And also remove a row by theindex>>>deltbl[1]>>>print(tbl)TABLE:default.sample+---+-----+---+|c1|c2|c3|+---+-----+---+0|4|Value|3.3|1|3|Some|0.0|+---+-----+---+Relational algebraThe main purpose of the relational algebra is to define operators that transform one or more input relations to an output relation. Given that these operators accept relations as input and produce relations as output, they can be combined and used to express potentially complex queries that transform potentially many input relations (whose data are stored in the database) into a single output relation (the query results).This are the current operations supported:SimboloOpradorOperaçãoSintaxe∪+UnionA + B∩%IntersectionA % B--DifferenceA – B×*ProductA * BππProjectA.π(<attribute list>)σσSelectA.σ([<logic functions>])ρρRenameA.ρ(name)ΠΠExtendA.Π(<arithmetic functions>)⋈ᐅᐊJoinA.ᐅᐊ( B,<logic functions>)DatabaseThis object represents a physical location on the file system with a set oftablesfromcsvms.schemaimportDatabasedb=Database("dbname")This will create a new directory, if not exists, inside$CSVMS_FILE_DIRpath
In most cases will not be necessary explicitly create this object because the Database is implicit created based on theTablename using the notationdatabase.table_nameFor more informatios usehelp(Database)CatalogWhen you instantiate an object the Catalog objet will save thetabledefinitions for future queries and save injson formaton root directory.fromcsvms.catalogimportCatalogcat=Catalog('file/system/location/path')In the path used to initialize the catalog contains the$CSVMS CATALOGjsonfile with all table definitions{"default.sample":{"name":"default.sample","columns":{"c1":"integer","c2":"text","c3":"float"}}}Important: You don't need to explicit create the catalog. That will be automatic created when you initiate any tableFor more informatios usehelp(Catalog)