Skip to main content

horsql

An experimental SQL ORM that operates with Pandas DataFrames, offering the flexibility of dynamic querying without the need for model or schema definitions.

Install

$ pip install horsql

Connect

db = horsql.connect(
    database="mydb",
    host="localhost",
    port=5432,
    user="dev",
    password="dev",
    dialect="postgresql", # or "mysql"
    echo=False,
    pool_size=5, # defaults to 5
)

Querying

import horsql.operators as o

# Get all users
df = db.public.users.get()

# Get some columns of the users that are +18
df = db.public.users.get(columns=["user_name", "age"], age=o.EqualsOrGreaterThan(18))

# (Aggregation) get the average age by city from Brazil
df = db.public.users.get(columns=["city"], avg=["age"], country="Brazil")

# Distinct columns
df = db.public.users.get(distinct=["last_name"])

# get users that were born between those dates
df = db.public.users.get(birth_date=o.Between(["1998-01-01", "2000-01-01"]))

# get users that it's last_name is Silva or Machado
df = db.public.users.get(last_name=["Silva", "Machado"])

# get users that it's last_name is not Silva or Machado
df = db.public.users.get(last_name=o.Not(["Silva", "Machado"]))

# get users from Brazil or those that have "Silva" as last_name
df = db.public.users.get(
    where=o.Or(
        country="Brazil",
        last_name="Silva"
    )
)

# get users from United States OR those that have "Smith" as last_name
# OR (first_name is "Wilian" AND last_name is "Silva")
df = db.public.users.get(
    where=o.Or(
        country="United States",
        last_name="Smith",
        o.And(
            first_name="Wilian",
            last_name="Silva"
        )
    )
)

# Ordering
df = db.public.users.order_by("age", ascending=True).get()

df = db.public.users.order_by(["age", "country"], ascending=[True, False]).get()

# Limit
df = db.public.users.limit(limit=10).get()

df = db.public.users.order_by("age", ascending=True).limit(limit=10).get()

# Pagination
df = db.public.users.paginate(page=1, page_size=10).get()

df = db.public.users.order_by("age", ascending=True).paginate(page=1, page_size=10).get()

Creating/Updating records in the database

new_user = pd.DataFrame([
    {
        "user_name": "WilianZilv",
        "first_name": "Wilian",
        "last_name": "Silva"
    }
])

# Create new records based on a dataframe
db.public.users.create(new_user)

# Upsert
db.public.users.create(new_user, on_conflict=["user_name"], update=["city", "country"])

# Updating records
new_user["city"] = "Curitiba"
new_user["country"] = "Brazil"

db.public.users.update(new_user, on_conflict=["user_name"], update=["city", "country"])

# Delete records
db.public.users.delete(user_name="WilianZilv")

Function definitions

Columns = Union[str, List[str]]

# Functions available in the Table object

def get(
    self,
    columns: Optional[Columns] = None,
    distinct: Optional[Columns] = None,
    min: Optional[Columns] = None,
    max: Optional[Columns] = None,
    sum: Optional[Columns] = None,
    avg: Optional[Columns] = None,
    count: Optional[Columns] = None,
    where: Optional[Union[And, Or]] = None,
    **and_where,
):
    ...

def create(
    self,
    df: pd.DataFrame,
    on_conflict: Optional[Columns] = None,
    update: Optional[Columns] = None,
    commit: bool = True,
):
    ...

def update(
    self,
    df: pd.DataFrame,
    on_conflict: Columns,
    update: Columns,
    commit: bool = True,
):
    ...

def limit(self, limit: int):
    ...

def paginate(self, page: int, page_size: int):
    ...

def order_by(
    self,
    columns: Union[List[str], str],
    ascending: Union[List[bool], bool] = []
):
    ...

Metadata

Release files for horsql 0.1.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for horsql 0.1.22
File Size Uploaded Provenance
horsql-0.1.22.tar.gz 7.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for horsql 0.1.22
File Interpreter ABI Platform
horsql-0.1.22-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / horsql-0.1.22.tar.gz

Download URL horsql-0.1.22.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bd75335e732a17ddd35f565cb1fe70c4cae95393e40961610f1cd4af2dc0c9f7
BLAKE2b-256 checksum
How to use checksums
962b48cfd000920ba5c57aae70010809b21771cab708730cab33350322cdd9e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / horsql-0.1.22-py3-none-any.whl

Download URL horsql-0.1.22-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95ef319812a3c27b361f222b3aff0d32865491c74da35f30b1e7cb9bfd929ee6
BLAKE2b-256 checksum
How to use checksums
8617321cebf1b79f866ed951c575cce0fcfa1f1aec7785edbdf51b916fc685c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Security for horsql 0.1.22

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page