A relational database -like table of rows.
Project description
RelaTable
A relational database -like table of rows.
Supports foreign key -style referencing to an another RelaTable
or other containers.
An Example
from relatable import RelaTable
colors = ["red", "blue", "green"]
pet_names = {"dog": "Musti", "cat": "Mirri"}
persons = RelaTable(
primary_key_column="id",
foreign_keys={"color": colors},
rows=[
{"id": 123, "name": "Jaakko", "color": 0},
{"id": 456, "name": "Teppo", "color": 1},
],
)
# Insert new user in the middle of the table
persons.insert(1, {"id": 789, "name": "Seppo", "color": 2})
pets = RelaTable(
# No primary key defined => index is used
foreign_keys={"name": pet_names, "owner": persons},
rows=[
{"name": "cat", "owner": 123}, # index 0
{"name": "dog", "owner": 456}, # index 1
],
)
print(persons)
# Prints out:
# [{'id': 123, 'name': 'Jaakko', 'color': 'red'},
# {'id': 789, 'name': 'Seppo', 'color': 'green'},
# {'id': 456, 'name': 'Teppo', 'color': 'blue'}]
print(pets)
# Prints out:
# [{'name': 'Mirri', 'owner': {'id': 123, 'name': 'Jaakko', 'color': 'red'}},
# {'name': 'Musti', 'owner': {'id': 456, 'name': 'Teppo', 'color': 'blue'}}]
print(persons[789].name)
# Prints out:
# Seppo
print(pets[0].owner.color)
# Prints out:
# red
print(pets[0].data())
# Prints out the non-expanded row data:
# {'name': 'cat', 'owner': 123}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file talamus_relatable-1.0.1.tar.gz
.
File metadata
- Download URL: talamus_relatable-1.0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba381eaf160125dcd1bc67ebf6fa9010ac8f572876a0e37f8de71074022b9988 |
|
MD5 | bc410368abf8d99a93b08aa588cb0259 |
|
BLAKE2b-256 | 6264d01e9b1741746fdbc3d2a5d9191c89314e774f9a093f414fec210b145e49 |
File details
Details for the file talamus_relatable-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: talamus_relatable-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57ea730e28248533864bd663680ce0f6a9ccd0a9e7a2fc1ec0ee3ee49316cf5e |
|
MD5 | af2d5f16a7e69d375f8a5e5b288be5fa |
|
BLAKE2b-256 | 49b83ee1357e3416a0fcd4b817dd1b726c0458ed16188a6edaa4af714f9ec864 |