https://github.com/zacharyvoase/relations
A tiny relational algebra engine for Python.
https://github.com/zacharyvoase/relations
Last synced: 3 months ago
JSON representation
A tiny relational algebra engine for Python.
- Host: GitHub
- URL: https://github.com/zacharyvoase/relations
- Owner: zacharyvoase
- License: unlicense
- Created: 2012-01-20T15:36:51.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-01-23T00:41:15.000Z (over 13 years ago)
- Last Synced: 2024-11-09T22:41:30.905Z (11 months ago)
- Language: Python
- Homepage:
- Size: 117 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Relations
Relations is a simple Python implementation of a relational algebra engine.
## Example
Create a relation with a heading (i.e. a list of field names):
>>> import relations
>>> employees = relations.Relation('employee_name', 'dept_name')
>>> employees
The fields are re-ordered alphabetically, so that the order of values in tuples
is consistent between equivalent but separate relations. Add tuples to the
relation:>>> alice = employees.add(employee_name='Alice', dept_name='Finance')
>>> bob = employees.add(employee_name='Bob', dept_name='Sales')
>>> len(employees)
2A relation is a set; duplicate tuples are considered identical:
>>> _ = employees.add(employee_name='Alice', dept_name='Finance')
>>> len(employees)
2A relation implements the relational algebra, including the unary operators
**Select**:>>> finance_emps = employees.select(lambda emp: emp.dept_name == 'Finance')
>>> len(finance_emps)
1**Project**:
>>> names = employees.project('employee_name')
>>> names.contains(employee_name='Bob')
True
>>> names.contains(employee_name='Charlie')
Falseand **Rename**:
>>> employees_renamed = employees.rename(name='employee_name')
>>> employees_renamed.contains(name='Bob')
TrueIt also supports the set operations **Union**, **Intersection** and
**Difference**.## Coming Soon
Joins:
* Natural join
* Theta join
* Equijoin
* Semijoin
* Antijoin
* Divide
* Left outer join
* Right outer join
* Full outer join## (Un)license
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.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 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.For more information, please refer to