dataclassesdb
Generates SQL and NoSQL database models from @dataclass
Documentation: https://dutradda.github.io/dataclassesdb
Source Code: https://github.com/dutradda/dataclassesdb
Key Features
-
Fast start data modeling with persistence
-
Supports from simple database schemas to complex one
-
Integrate with:
SQLALchemyaioredis(soon)google-datastore(soon)mongodb(planned)elasticsearch(planned)aws-dynamodb(planned)
-
Same interface as
sqlalchemy.orm.session.Session -
Easy integration with other data sources
-
Supports redis data structure (like hashs, sets, etc) to store objects
Requirements
Python 3.7+
Instalation
$ pip install dataclassesdb
Basic SQLAlchemy example
import asyncio
from dataclassesdb import DataSourceType, SessionFactory
from dataclasses import dataclass
@dataclass
class Music:
name: str
@dataclass
class Person:
name: str
age: int
music: Music
session = SessionFactory.make(
Music,
Person,
data_source=DataSourceType.RELATIONAL_SQLALCHEMY,
data_source_args=dict(
db_url='sqlite://',
backrefs=True,
create_tables=True,
)
)
person = Person(
name='John',
age=40,
music=Music('Imagine')
)
session.add(person) # commit=True by default
musicQuery = session.query(Address)
musics = musicQuery.filter(name='Imagine').all()
loop = asyncio.get_event_loop()
print(loop.run_until_complete(musics))
[
Music(
name='Imagine',
_id=1,
backrefs=Backrefs(
person=[Person(age=40, name=John, _id=1)]
)
)
]
Basic aioredis with hash data type example
import asyncio
from dataclassesdb import DataSourceType, SessionFactoryAsync
from dataclasses import dataclass
@dataclass
class Music:
name: str
@dataclass
class Person:
name: str
age: int
music: Music
async def get_musics():
session = await SessionFactoryAsync.make(
Address,
Person,
data_source=DataSourceType.MEMORY_AIOREDIS,
data_source_args=dict(
db_url='redis://',
backrefs=True,
)
)
person = Person(
name='John',
age=40,
music=Music('Imagine')
)
await session.add(person)
musicQuery = await session.query(Address)
return await musicQuery.filter(name='Imagine').all()
loop = asyncio.get_event_loop()
print(loop.run_until_complete(musics))
[
Music(
name='Imagine',
_id=1,
backrefs=Backrefs(
person=[Person(age=40, name=John, _id=1)]
)
)
]
Basic aioredis with sorted set data type example
from dataclassesdb import (
DataSourceType,
MemorySortedSetRanked,
ModelKey,
SessionFactoryAsync,
SortedValue,
)
from dataclasses import dataclass
@dataclass
class Music:
id: ModelKey(str)
name: str
class Playlist(MemorySortedSetRanked):
value_type = Music
@dataclass
class Person:
name: str
age: int
playlist: Playlist
session = await SessionFactoryAsync.make(
Music,
Playlist,
Person,
data_source=DataSourceType.MEMORY_AIOREDIS,
data_source_args=dict(
db_url='redis://',
backrefs=True,
)
)
person = Person(
name='John',
age=40,
playlist=Playlist(
Music(id='imagine', name='Imagine'),
Music(id='come-together', name='Come Together'),
)
)
await session.add(person)
playlistQuery = await session.query(Playlist)
playlist = await playlistQuery.filter(Person.name=='John').one(withrank=True)
print(playlist)
[
SortedValue(
rank=1,
key='imagine'
),
SortedValue(
rank=2,
key='come-together'
)
]
Metadata
Release files for dataclassesdb 0.0.11
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 |
|---|---|---|---|---|
| dataclassesdb-0.0.11.tar.gz | 14.7 kB | Without provenance | Details for dataclassesdb-0.0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dataclassesdb-0.0.11-py3-none-any.whl | Python 3 | none | any | Details for dataclassesdb-0.0.11-py3-none-any.whl |
Total release size: 18.7 kB
Release files / dataclassesdb-0.0.11.tar.gz
| Download URL | dataclassesdb-0.0.11.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
978c2137e6a58d43a40791d543170b213dd33c4d8218322c15da35f3e053d664
|
|
BLAKE2b-256 checksum How to use checksums |
696a8603b6ce811d946a4a16f7676e091beb9a682fcfa3636d553b4ff37ca00c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.22.0
|
Release files / dataclassesdb-0.0.11-py3-none-any.whl
| Download URL | dataclassesdb-0.0.11-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4bcdf612415bc9dfe964981491c1ca3c2be580554fadf5635af7658688603925
|
|
BLAKE2b-256 checksum How to use checksums |
e6b0e50b687329be5bc1dc792c456765cf4ebdcdc13ce46bbace7b851c2d6594
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.22.0
|
Security for dataclassesdb 0.0.11
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.