yesql is a SQL-first data access library that will replace your ORM.
Project description
yesql
Say yes to SQL with yesql.
yesql eliminates boilerplate without the baggage of an expensive or clunky ORM. Simply write your SQL, point yesql to the directory, and it does all the rest.
Quickstart
Installation
pip install -U --pre yesql
or
poetry add --allow-prereleases yesql
yesql currently supports the following database drivers:
You can select your driver as an extra when installing yesql (recommended):
pip install -U --pre "yesql[psycopg]"
or
poetry add --allow-prereleases yesql -E asyncpg
Basic Usage
from __future__ import annotations
import dataclasses
import datetime
import pathlib
import yesql
QUERIES = pathlib.Path(__file__).resolve().parent / "queries"
@dataclasses.dataclass(slots=True, kw_only=True)
class Post:
id: int | None = None
slug: str | None = None
title: str | None = None
subtitle: str | None = None
tagline: str | None = None
body: str | None = None
tags: set[str] = dataclasses.field(default_factory=set)
publication_date: datetime.date | None = None
created_at: datetime.datetime | None = None
updated_at: datetime.datetime | None = None
class PostsRepository(yesql.SyncQueryRepository[Post]):
"""An asyncio-native service for querying blog posts."""
class metadata(yesql.QueryMetadata):
__querylib__ = QUERIES
__tablename__ = "posts"
__exclude_fields__ = frozenset(("slug",))
posts = PostsRepository()
posts.initialize()
new_post = Post(
title="My Great Blog Post",
subtitle="It's super great. Trust me...",
tagline="You'll be glad you read it.",
tags={"tips", "tricks", "cool stuff"},
)
saved_post = posts.create(instance=new_post)
Type-stub Generation (Experimental)
yesql ships with simple CLI for generating type-stubs. This allows for more exact static type-analysis and enables auto-complete for your IDE.
Usage:
yesql stubgen
You can optionally supply any number of paths to directories or python modules. The command will default to the current working directory on the filesystem.
If you don't have black installed in your development environment, you should add
the cli
extra as a development dependency.
Features
- Support for synchronous IO
- Support for asynchronous IO (asyncio)
- Support for PostgreSQL
- Plays well with MyPy
- Plays well with IDEs
- Encourages best-practices for data-access (Separation of Concerns, Repository Pattern)
No ORMs?
-
ORMs are bad for you.
They are a leaky abstraction that cannot solve the problem they set out to do - which is to abstract out the details of working with a database. -
ORMs are slow.
ORMs depend upon a high level of abstraction in order to work across database clients. They also attempt to bridge the gap of data validation and state management. By attempting to hide the details of managing state from the end user, they suffer from large computational costs and predict -
ORMs are wasteful.
As mentioned above, ORMs use a huge amount of resources to auto-magically determine state for anything and everything currently pulled into your application's memory. Because this is implicit, this takes a large amount of work to do right. In general, your application is already aware of "clean" and "dirty" states. Your application should be in charge of managing it. -
ORMs encourage bad data modeling.
ORMs vastly simplify recursive data modeling (see: N+1 problem) which encourages lazy solutions to simple problems and can result in extreme service degradation without reasonable means of mitigation.
Why yesql?
yesql takes a SQL-first approach to data management:
-
Focus on your SQL and your database.
- Reduce developer overhead by having one less middleman between you and your data.
- Easily fine-tune your SQL to take full advantage of the RDBMS you choose.
- No guesswork about what SQL is actually being executed on your database.
-
Explicit state management.
- No surprise writes or reads, you control when you read and when you write.
- There is no question whether data is in-memory or in the database.
-
Plain Ol' Data Objects.
- Model your data with a mapping, a namedtuple, a dataclass, or just use the native record objects of your preferred library.
- Loose ser/des based on your model, which can be overridden at any point.
- No implicit state mapping of data from a table to your model. Your query powers your model.
v1.0.0 Roadmap
- Query Library Bootstrapping
- Dynamic Query Library
- Full Documentation Coverage
- Full Test Coverage
- Dialect Support
- Async PostgreSQL (via asyncpg & psycopg3)
- Async SQLite
- Async MySQL
- Sync PostgreSQL
- Sync SQLite
- Sync MySQL
License
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 yesql-1.0.0b4.tar.gz
.
File metadata
- Download URL: yesql-1.0.0b4.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/5.15.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8a0be0771212a0e455a0e1a59f70b97260393b4ae167bf203b967c2d96187b |
|
MD5 | 57384e276516750ae3c22d0163994720 |
|
BLAKE2b-256 | a4c36011166e58a25801ea9959aa25f7412c65aeafb3db6860386647dc6dd903 |
File details
Details for the file yesql-1.0.0b4-py3-none-any.whl
.
File metadata
- Download URL: yesql-1.0.0b4-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/5.15.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eeb27a7b6d51472dfddf0fe1d271f9310ebc0f1010a62400c8e360c68fb20d2 |
|
MD5 | 1b021d1eaf7f78002353cdf5b375c2e5 |
|
BLAKE2b-256 | d4b740c536228857f634a55838e7d8086d934a07e76c4b02dd2acf36b3ec6ab3 |