relationaldb
RelationalDB is a python ODM library for MongoDB that allows you to design collections like you do it for your normal dataclasses objects.
DISCLAMER
This library is in alpha-release, it's a work in progress for the moment, excellent libraries for MongoDB ODM in python exist:
There are a lot of none implemented main features (I implement them when I have time or when I need it for my project).
Quickstart
relationaldb wraps attrs to create classes boilerplate and add few parameters.
One to Many relation
Let's say you want a simple one to many relations, with two entities: Animal and Person.
- Each animal can have one owner (Person)
- Each person can have 0 to many animals
from relationaldb import conception
# Object to design the architecture of the database
c = conception()
# Add collection woth 'define' like with attrs
@c.define
class Person:
# add new attribute with 'field' method
# in_filter_query parameter allows to use the 'db.Person.feed' method to upsert new documents
name: str = c.field(in_filter_query=True)
# all attrs.fields parameters are available
money: int = c.field(kw_only=True, default=0)
birth_year: int = c.field(kw_only=True, default=None)
@c.define
class Animal:
# We can reference
name: Person = c.field(in_filter_query=True)
owner: Person = c.field(kw_only=True, default=None)
birth_year: int = c.field(kw_only=True, default=None)
# Create a new mongodb named "mydb"
db = c.mongodb("relationaldb_mydb_01")
# Create second DB with same architecture
db2 = c.mongodb("relationaldb_mydb_02")
# Create a new person
db.Person.insert_one("John")
# Get the person
person = db.Person.first()
assert isinstance(person, Person)
assert person.name == "John"
for person in db.Person:
print(person)
# Upsert (create or update) person named 'Smith' if it does not exists (based on in_filter_query)
db.Person.feed("Smith") # will create the person
db.Person.feed("Smith") # will do nothing, person already exist
db.Person.feed("Smith", money=1000) # will update the person 'Smith'
Metadata
Release files for relationaldb 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| relationaldb-0.1.1.tar.gz | 13.7 kB | Without provenance | Details for relationaldb-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| relationaldb-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for relationaldb-0.1.1-py3-none-any.whl |
Total release size: 33.3 kB
Release files / relationaldb-0.1.1.tar.gz
| Download URL | relationaldb-0.1.1.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
336f63609ba855fd271cc6822e3e9ce1e452b4544b8f56d290a6ea4840137b49
|
|
BLAKE2b-256 checksum How to use checksums |
27230f5db1bf41f753184df4829515f2d64fbfed7195a068a83a10ca707dc585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.28.1 setuptools/49.2.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / relationaldb-0.1.1-py3-none-any.whl
| Download URL | relationaldb-0.1.1-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b55567d844df07e560fdd95fc5e5598552dd344946042e0dbd99e5560385ff9d
|
|
BLAKE2b-256 checksum How to use checksums |
938a7eee11bdd5f4a6ee43b83e5e5433f1821144d7c701aa9d2c14c19ab9b012
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.28.1 setuptools/49.2.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Security for relationaldb 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.