scyllapy


Namescyllapy JSON
Version 1.3.1 PyPI version JSON
download
home_pageNone
SummaryAsync scylla driver for python
upload_time2024-04-20 09:46:30
maintainerNone
docs_urlNone
authorNone
requires_python<4,>=3.8
licenseNone
keywords scylla cassandra async-driver scylla-driver
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI](https://img.shields.io/pypi/v/scyllapy?style=for-the-badge)](https://pypi.org/project/scyllapy/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/scyllapy?style=for-the-badge)](https://pypistats.org/packages/scyllapy)


# Async Scylla driver for python

Python driver for ScyllaDB written in Rust. Though description says it's for scylla,
however it can be used with Cassandra and AWS keyspaces as well.

This driver uses official [ScyllaDB driver](https://github.com/scylladb/scylla-rust-driver) for [Rust](https://github.com/rust-lang/rust/) and exposes python API to interact with it.

## Installation

To install it, use your favorite package manager for python packages:

```bash
pip install scyllapy
```

Also, you can build from sources. To do it, install stable rust, [maturin](https://github.com/PyO3/maturin) and openssl libs.

```bash
maturin build --release --out dist
# Then install whl file from dist folder.
pip install dist/*
```

## Usage

The usage is pretty straitforward. Create a Scylla instance, run startup and start executing queries.

```python
import asyncio

from scyllapy import Scylla


async def main():
    scylla = Scylla(["localhost:9042"], keyspace="keyspace")
    await scylla.startup()
    await scylla.execute("SELECT * FROM table")
    await scylla.shutdown()

if __name__ == "__main__":
    asyncio.run(main())

```

## Parametrizing queries

While executing queries sometimes you may want to fine-tune some parameters, or dynamically pass values to the query.

Passing parameters is simple. You need to add a paramters list to the query.

```python
    await scylla.execute(
        "INSERT INTO otps(id, otp) VALUES (?, ?)",
        [uuid.uuid4(), uuid.uuid4().hex],
    )
```

Queries can be modified further by using `Query` class. It allows you to define
consistency for query or enable tracing.

```python
from scyllapy import Scylla, Query, Consistency, SerialConsistency

async def make_query(scylla: Scylla) -> None:
    query = Query(
        "SELECT * FROM table",
        consistency=Consistency.ALL,
        serial_consistency=SerialConsistency.LOCAL_SERIAL,
        request_timeout=1,
        timestamp=int(time.time()),
        is_idempotent=False,
        tracing=True,
    )
    result = await scylla.execute(query)
    print(result.all())
```

Also, with queries you can tweak random parameters for a specific execution.

```python
query = Query("SELECT * FROM table")

new_query = query.with_consistency(Consistency.ALL)
```

All `with_` methods create new query, copying all other parameters.

Here's the list of scylla types and corresponding python types that you should use while passing parameters to queries:

| Scylla type | Python type            |
| ----------- | ---------------------- |
| int         | int                    |
| tinyint     | extra_types.TinyInt    |
| bigint      | extra_types.BigInt     |
| varint      | any int type           |
| float       | float                  |
| double      | extra_types.Double     |
| decimal     | decimal.Decimal        |
| ascii       | str                    |
| text        | str                    |
| varchar     | str                    |
| blob        | bytes                  |
| boolean     | bool                   |
| counter     | extra_types.Counter    |
| date        | datetime.date          |
| uuid        | uuid.UUID              |
| inet        | ipaddress              |
| time        | datetime.time          |
| timestamp   | datetime.datetime      |
| duration    | dateutil.relativedelta |

All types from `extra_types` module are used to eliminate any possible ambiguity while passing parameters to queries. You can find more information about them in `Extra types` section.

We use relative delta from `dateutil` for duration, because it's the only way to represent it in python. Since scylla operates with months, days and nanosecond, there's no way we can represent it in python, becuase months are variable length.


## Named parameters

Also, you can provide named parameters to querties, by using name
placeholders instead of `?`.

For example:

```python
async def insert(scylla: Scylla):
    await scylla.execute(
        "INSERT INTO table(id, name) VALUES (:id, :name)",
        params={"id": uuid.uuid4(), "name": uuid.uuid4().hex}
    )
```

Important note: All variables should be in snake_case.
Otherwise the error may be raised or parameter may not be placed in query correctly.
This happens, because scylla makes all parameters in query lowercase.

The scyllapy makes all parameters lowercase, but you may run into problems,
if you use multiple parameters that differ only in cases of some letters.


## Preparing queries

Also, queries can be prepared. You can either prepare raw strings, or `Query` objects.

```python
from scyllapy import Scylla, Query, PreparedQuery


async def prepare(scylla: Scylla, query: str | Query) -> PreparedQuery:
    return await scylla.prepare(query)
```

You can execute prepared queries by passing them to `execute` method.

```python
async def run_prepared(scylla: Scylla) -> None:
    prepared = await scylla.prepare("INSERT INTO memse(title) VALUES (?)")
    await scylla.execute(prepared, ("American joke",))
```

### Batching

We support batches. Batching can help a lot when you have lots of queries that you want to execute at the same time.

```python
from scyllapy import Scylla, Batch


async def run_batch(scylla: Scylla, num_queries: int) -> None:
    batch = Batch()
    for _ in range(num_queries):
        batch.add_query("SELECT * FROM table WHERE id = ?")
    await scylla.batch(batch, [(i,) for i in range(num_queries)])
```

Here we pass query as strings. But you can also add Prepared statements or Query objects.

Also, note that we pass list of lists as parametes for execute. Each element of
the list is going to be used in the query with the same index. But named parameters
are not supported for batches.

```python
async def run_batch(scylla: Scylla, num_queries: int) -> None:
    batch = Batch()
    batch.add_query("SELECT * FROM table WHERE id = :id")
    await scylla.batch(batch, [{"id": 1}])  # Will rase an error!
```

## Pagination

Sometimes you want to query lots of data. For such cases it's better not to
fetch all results at once, but fetch them using pagination. It reduces load
not only on your application, but also on a cluster.

To execute query with pagination, simply add `paged=True` in execute method.
After doing so, `execute` method will return `IterableQueryResult`, instead of `QueryResult`.
Instances of `IterableQueryResult` can be iterated with `async for` statements.
You, as a client, won't see any information about pages, it's all handeled internally within a driver.

Please note, that paginated queries are slower to fetch all rows, but much more memory efficent for large datasets.

```python
    result = await scylla.execute("SELECT * FROM table", paged=True)
    async for row in result:
        print(row)

```

Of course, you can change how results returned to you, by either using `scalars` or
`as_cls`. For example:

```python
async def func(scylla: Scylla) -> None:
    rows = await scylla.execute("SELECT id FROM table", paged=True)
    # Will print ids of each returned row.
    async for test_id in rows.scalars():
        print(test_id)

```

```python
from dataclasses import dataclass

@dataclass
class MyDTO:
    id: int
    val: int

async def func(scylla: Scylla) -> None:
    rows = await scylla.execute("SELECT * FROM table", paged=True)
    # Will print ids of each returned row.
    async for my_dto in rows.as_cls(MyDTO):
        print(my_dto.id, my_dto.val)

```

## Execution profiles

You can define profiles using `ExecutionProfile` class. After that the
profile can be used while creating a cluster or when defining queries.

```python
from scyllapy import Consistency, ExecutionProfile, Query, Scylla, SerialConsistency
from scyllapy.load_balancing import LoadBalancingPolicy, LatencyAwareness

default_profile = ExecutionProfile(
    consistency=Consistency.LOCAL_QUORUM,
    serial_consistency=SerialConsistency.LOCAL_SERIAL,
    request_timeout=2,
)

async def main():
    query_profile = ExecutionProfile(
        consistency=Consistency.ALL,
        serial_consistency=SerialConsistency.SERIAL,
        # Load balancing cannot be constructed without running event loop.
        # If you won't do it inside async funcion, it will result in error.
        load_balancing_policy=await LoadBalancingPolicy.build(
            token_aware=True,
            prefer_rack="rack1",
            prefer_datacenter="dc1",
            permit_dc_failover=True,
            shuffling_replicas=True,
            latency_awareness=LatencyAwareness(
                minimum_measurements=10,
                retry_period=1000,
                exclusion_threshold=1.4,
                update_rate=1000,
                scale=2,
            ),
        ),
    )

    scylla = Scylla(
        ["192.168.32.4"],
        default_execution_profile=default_profile,
    )
    await scylla.startup()
    await scylla.execute(
        Query(
            "SELECT * FROM system_schema.keyspaces;",
            profile=query_profile,
        )
    )
```

### Results

Every query returns a class that represents returned rows. It allows you to not fetch
and parse actual data if you don't need it. **Please be aware** that if your query was
not expecting any rows in return. Like for `Update` or `Insert` queries. The `RuntimeError` is raised when you call `all` or `first`.

```python
result = await scylla.execute("SELECT * FROM table")
print(result.all())
```

If you were executing query with tracing, you can get tracing id from results.

```python
result = await scylla.execute(Query("SELECT * FROM table", tracing=True))
print(result.trace_id)
```

Also it's possible to parse your data using custom classes. You
can use dataclasses or Pydantic.

```python
from dataclasses import dataclass

@dataclass
class MyDTO:
    id: uuid.UUID
    name: str

result = await scylla.execute("SELECT * FROM inbox")
print(result.all(as_class=MyDTO))
```

Or with pydantic.

```python
from pydantic import BaseModel

class MyDTO(BaseModel):
    user_id: uuid.UUID
    chat_id: uuid.UUID

result = await scylla.execute("SELECT * FROM inbox")
print(result.all(as_class=MyDTO))
```

## Extra types

Since Rust enforces typing, it's hard to identify which value
user tries to pass as a parameter. For example, `1` that comes from python
can be either `tinyint`, `smallint` or even `bigint`. But we cannot say for sure
how many bytes should we send to server. That's why we created some extra_types to
eliminate any possible ambigousnity.

You can find these types in `extra_types` module from scyllapy.

```python
from scyllapy import Scylla, extra_types

async def execute(scylla: Scylla) -> None:
    await scylla.execute(
        "INSERT INTO table(id, name) VALUES (?, ?)",
        [extra_types.BigInt(1), "memelord"],
    )
```

## User defined types

We also support user defined types. You can pass them as a parameter to query.
Or parse it as a model in response.

Here's binding example. Imagine we have defined a type in scylla like this:

```cql
CREATE TYPE IF NOT EXISTS test (
    id int,
    name text
);
```

Now we need to define a model for it in python.

```python
from dataclasses import dataclass
from scyllapy.extra_types import ScyllaPyUDT

@dataclass
class TestUDT(ScyllaPyUDT):
    # Always define fields in the same order as in scylla.
    # Otherwise you will get an error, or wrong data.
    id: int
    name: str

async def execute(scylla: Scylla) -> None:
    await scylla.execute(
        "INSERT INTO table(id, udt_col) VALUES (?, ?)",
        [1, TestUDT(id=1, name="test")],
    )

```

We also support pydantic based models. Decalre them like this:

```python
from pydantic import BaseModel
from scyllapy.extra_types import ScyllaPyUDT


class TestUDT(BaseModel, ScyllaPyUDT):
    # Always define fields in the same order as in scylla.
    # Otherwise you will get an error, or wrong data.
    id: int
    name: str

```

# Query building

ScyllaPy gives you ability to build queries,
instead of working with raw cql. The main advantage that it's harder to make syntax error,
while creating queries.

Base classes for Query building can be found in `scyllapy.query_builder`.

Usage example:

```python
from scyllapy import Scylla
from scyllapy.query_builder import Insert, Select, Update, Delete


async def main(scylla: Scylla):
    await scylla.execute("CREATE TABLE users(id INT PRIMARY KEY, name TEXT)")

    user_id = 1

    # We create a user with id and name.
    await Insert("users").set("id", user_id).set(
        "name", "user"
    ).if_not_exists().execute(scylla)

    # We update it's name to be user2
    await Update("users").set("name", "user2").where("id = ?", [user_id]).execute(
        scylla
    )

    # We select all users with id = user_id;
    res = await Select("users").where("id = ?", [user_id]).execute(scylla)
    # Verify that it's correct.
    assert res.first() == {"id": 1, "name": "user2"}

    # We delete our user.
    await Delete("users").where("id = ?", [user_id]).if_exists().execute(scylla)

    res = await Select("users").where("id = ?", [user_id]).execute(scylla)

    # Verify that user is deleted.
    assert not res.all()

    await scylla.execute("DROP TABLE users")

```

Also, you can pass built queries into InlineBatches. You cannot use queries built with query_builder module with default batches. This constraint is exists, because we
need to use values from within your queries and should ignore all parameters passed in
`batch` method of scylla.

Here's batch usage example.

```python
from scyllapy import Scylla, InlineBatch
from scyllapy.query_builder import Insert


async def execute_batch(scylla: Scylla) -> None:
    batch = InlineBatch()
    for i in range(10):
        Insert("users").set("id", i).set("name", "test").add_to_batch(batch)
    await scylla.batch(batch)

```

## Paging

Queries that were built with QueryBuilder also support paged returns.
But it supported only for select, because update, delete and insert should
not return anything and it makes no sense implementing it.
To make built `Select` query return paginated iterator, add paged parameter in execute method.

```python
    rows = await Select("test").execute(scylla, paged=True)
    async for row in rows:
        print(row['id'])
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "scyllapy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.8",
    "maintainer_email": null,
    "keywords": "scylla, cassandra, async-driver, scylla-driver",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b8/2c/f45fe7eb1255590ec00c8b99b73b612aabec42d9adb609e1ad4f00b718ff/scyllapy-1.3.1.tar.gz",
    "platform": null,
    "description": "[![PyPI](https://img.shields.io/pypi/v/scyllapy?style=for-the-badge)](https://pypi.org/project/scyllapy/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/scyllapy?style=for-the-badge)](https://pypistats.org/packages/scyllapy)\n\n\n# Async Scylla driver for python\n\nPython driver for ScyllaDB written in Rust. Though description says it's for scylla,\nhowever it can be used with Cassandra and AWS keyspaces as well.\n\nThis driver uses official [ScyllaDB driver](https://github.com/scylladb/scylla-rust-driver) for [Rust](https://github.com/rust-lang/rust/) and exposes python API to interact with it.\n\n## Installation\n\nTo install it, use your favorite package manager for python packages:\n\n```bash\npip install scyllapy\n```\n\nAlso, you can build from sources. To do it, install stable rust, [maturin](https://github.com/PyO3/maturin) and openssl libs.\n\n```bash\nmaturin build --release --out dist\n# Then install whl file from dist folder.\npip install dist/*\n```\n\n## Usage\n\nThe usage is pretty straitforward. Create a Scylla instance, run startup and start executing queries.\n\n```python\nimport asyncio\n\nfrom scyllapy import Scylla\n\n\nasync def main():\n    scylla = Scylla([\"localhost:9042\"], keyspace=\"keyspace\")\n    await scylla.startup()\n    await scylla.execute(\"SELECT * FROM table\")\n    await scylla.shutdown()\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n\n```\n\n## Parametrizing queries\n\nWhile executing queries sometimes you may want to fine-tune some parameters, or dynamically pass values to the query.\n\nPassing parameters is simple. You need to add a paramters list to the query.\n\n```python\n    await scylla.execute(\n        \"INSERT INTO otps(id, otp) VALUES (?, ?)\",\n        [uuid.uuid4(), uuid.uuid4().hex],\n    )\n```\n\nQueries can be modified further by using `Query` class. It allows you to define\nconsistency for query or enable tracing.\n\n```python\nfrom scyllapy import Scylla, Query, Consistency, SerialConsistency\n\nasync def make_query(scylla: Scylla) -> None:\n    query = Query(\n        \"SELECT * FROM table\",\n        consistency=Consistency.ALL,\n        serial_consistency=SerialConsistency.LOCAL_SERIAL,\n        request_timeout=1,\n        timestamp=int(time.time()),\n        is_idempotent=False,\n        tracing=True,\n    )\n    result = await scylla.execute(query)\n    print(result.all())\n```\n\nAlso, with queries you can tweak random parameters for a specific execution.\n\n```python\nquery = Query(\"SELECT * FROM table\")\n\nnew_query = query.with_consistency(Consistency.ALL)\n```\n\nAll `with_` methods create new query, copying all other parameters.\n\nHere's the list of scylla types and corresponding python types that you should use while passing parameters to queries:\n\n| Scylla type | Python type            |\n| ----------- | ---------------------- |\n| int         | int                    |\n| tinyint     | extra_types.TinyInt    |\n| bigint      | extra_types.BigInt     |\n| varint      | any int type           |\n| float       | float                  |\n| double      | extra_types.Double     |\n| decimal     | decimal.Decimal        |\n| ascii       | str                    |\n| text        | str                    |\n| varchar     | str                    |\n| blob        | bytes                  |\n| boolean     | bool                   |\n| counter     | extra_types.Counter    |\n| date        | datetime.date          |\n| uuid        | uuid.UUID              |\n| inet        | ipaddress              |\n| time        | datetime.time          |\n| timestamp   | datetime.datetime      |\n| duration    | dateutil.relativedelta |\n\nAll types from `extra_types` module are used to eliminate any possible ambiguity while passing parameters to queries. You can find more information about them in `Extra types` section.\n\nWe use relative delta from `dateutil` for duration, because it's the only way to represent it in python. Since scylla operates with months, days and nanosecond, there's no way we can represent it in python, becuase months are variable length.\n\n\n## Named parameters\n\nAlso, you can provide named parameters to querties, by using name\nplaceholders instead of `?`.\n\nFor example:\n\n```python\nasync def insert(scylla: Scylla):\n    await scylla.execute(\n        \"INSERT INTO table(id, name) VALUES (:id, :name)\",\n        params={\"id\": uuid.uuid4(), \"name\": uuid.uuid4().hex}\n    )\n```\n\nImportant note: All variables should be in snake_case.\nOtherwise the error may be raised or parameter may not be placed in query correctly.\nThis happens, because scylla makes all parameters in query lowercase.\n\nThe scyllapy makes all parameters lowercase, but you may run into problems,\nif you use multiple parameters that differ only in cases of some letters.\n\n\n## Preparing queries\n\nAlso, queries can be prepared. You can either prepare raw strings, or `Query` objects.\n\n```python\nfrom scyllapy import Scylla, Query, PreparedQuery\n\n\nasync def prepare(scylla: Scylla, query: str | Query) -> PreparedQuery:\n    return await scylla.prepare(query)\n```\n\nYou can execute prepared queries by passing them to `execute` method.\n\n```python\nasync def run_prepared(scylla: Scylla) -> None:\n    prepared = await scylla.prepare(\"INSERT INTO memse(title) VALUES (?)\")\n    await scylla.execute(prepared, (\"American joke\",))\n```\n\n### Batching\n\nWe support batches. Batching can help a lot when you have lots of queries that you want to execute at the same time.\n\n```python\nfrom scyllapy import Scylla, Batch\n\n\nasync def run_batch(scylla: Scylla, num_queries: int) -> None:\n    batch = Batch()\n    for _ in range(num_queries):\n        batch.add_query(\"SELECT * FROM table WHERE id = ?\")\n    await scylla.batch(batch, [(i,) for i in range(num_queries)])\n```\n\nHere we pass query as strings. But you can also add Prepared statements or Query objects.\n\nAlso, note that we pass list of lists as parametes for execute. Each element of\nthe list is going to be used in the query with the same index. But named parameters\nare not supported for batches.\n\n```python\nasync def run_batch(scylla: Scylla, num_queries: int) -> None:\n    batch = Batch()\n    batch.add_query(\"SELECT * FROM table WHERE id = :id\")\n    await scylla.batch(batch, [{\"id\": 1}])  # Will rase an error!\n```\n\n## Pagination\n\nSometimes you want to query lots of data. For such cases it's better not to\nfetch all results at once, but fetch them using pagination. It reduces load\nnot only on your application, but also on a cluster.\n\nTo execute query with pagination, simply add `paged=True` in execute method.\nAfter doing so, `execute` method will return `IterableQueryResult`, instead of `QueryResult`.\nInstances of `IterableQueryResult` can be iterated with `async for` statements.\nYou, as a client, won't see any information about pages, it's all handeled internally within a driver.\n\nPlease note, that paginated queries are slower to fetch all rows, but much more memory efficent for large datasets.\n\n```python\n    result = await scylla.execute(\"SELECT * FROM table\", paged=True)\n    async for row in result:\n        print(row)\n\n```\n\nOf course, you can change how results returned to you, by either using `scalars` or\n`as_cls`. For example:\n\n```python\nasync def func(scylla: Scylla) -> None:\n    rows = await scylla.execute(\"SELECT id FROM table\", paged=True)\n    # Will print ids of each returned row.\n    async for test_id in rows.scalars():\n        print(test_id)\n\n```\n\n```python\nfrom dataclasses import dataclass\n\n@dataclass\nclass MyDTO:\n    id: int\n    val: int\n\nasync def func(scylla: Scylla) -> None:\n    rows = await scylla.execute(\"SELECT * FROM table\", paged=True)\n    # Will print ids of each returned row.\n    async for my_dto in rows.as_cls(MyDTO):\n        print(my_dto.id, my_dto.val)\n\n```\n\n## Execution profiles\n\nYou can define profiles using `ExecutionProfile` class. After that the\nprofile can be used while creating a cluster or when defining queries.\n\n```python\nfrom scyllapy import Consistency, ExecutionProfile, Query, Scylla, SerialConsistency\nfrom scyllapy.load_balancing import LoadBalancingPolicy, LatencyAwareness\n\ndefault_profile = ExecutionProfile(\n    consistency=Consistency.LOCAL_QUORUM,\n    serial_consistency=SerialConsistency.LOCAL_SERIAL,\n    request_timeout=2,\n)\n\nasync def main():\n    query_profile = ExecutionProfile(\n        consistency=Consistency.ALL,\n        serial_consistency=SerialConsistency.SERIAL,\n        # Load balancing cannot be constructed without running event loop.\n        # If you won't do it inside async funcion, it will result in error.\n        load_balancing_policy=await LoadBalancingPolicy.build(\n            token_aware=True,\n            prefer_rack=\"rack1\",\n            prefer_datacenter=\"dc1\",\n            permit_dc_failover=True,\n            shuffling_replicas=True,\n            latency_awareness=LatencyAwareness(\n                minimum_measurements=10,\n                retry_period=1000,\n                exclusion_threshold=1.4,\n                update_rate=1000,\n                scale=2,\n            ),\n        ),\n    )\n\n    scylla = Scylla(\n        [\"192.168.32.4\"],\n        default_execution_profile=default_profile,\n    )\n    await scylla.startup()\n    await scylla.execute(\n        Query(\n            \"SELECT * FROM system_schema.keyspaces;\",\n            profile=query_profile,\n        )\n    )\n```\n\n### Results\n\nEvery query returns a class that represents returned rows. It allows you to not fetch\nand parse actual data if you don't need it. **Please be aware** that if your query was\nnot expecting any rows in return. Like for `Update` or `Insert` queries. The `RuntimeError` is raised when you call `all` or `first`.\n\n```python\nresult = await scylla.execute(\"SELECT * FROM table\")\nprint(result.all())\n```\n\nIf you were executing query with tracing, you can get tracing id from results.\n\n```python\nresult = await scylla.execute(Query(\"SELECT * FROM table\", tracing=True))\nprint(result.trace_id)\n```\n\nAlso it's possible to parse your data using custom classes. You\ncan use dataclasses or Pydantic.\n\n```python\nfrom dataclasses import dataclass\n\n@dataclass\nclass MyDTO:\n    id: uuid.UUID\n    name: str\n\nresult = await scylla.execute(\"SELECT * FROM inbox\")\nprint(result.all(as_class=MyDTO))\n```\n\nOr with pydantic.\n\n```python\nfrom pydantic import BaseModel\n\nclass MyDTO(BaseModel):\n    user_id: uuid.UUID\n    chat_id: uuid.UUID\n\nresult = await scylla.execute(\"SELECT * FROM inbox\")\nprint(result.all(as_class=MyDTO))\n```\n\n## Extra types\n\nSince Rust enforces typing, it's hard to identify which value\nuser tries to pass as a parameter. For example, `1` that comes from python\ncan be either `tinyint`, `smallint` or even `bigint`. But we cannot say for sure\nhow many bytes should we send to server. That's why we created some extra_types to\neliminate any possible ambigousnity.\n\nYou can find these types in `extra_types` module from scyllapy.\n\n```python\nfrom scyllapy import Scylla, extra_types\n\nasync def execute(scylla: Scylla) -> None:\n    await scylla.execute(\n        \"INSERT INTO table(id, name) VALUES (?, ?)\",\n        [extra_types.BigInt(1), \"memelord\"],\n    )\n```\n\n## User defined types\n\nWe also support user defined types. You can pass them as a parameter to query.\nOr parse it as a model in response.\n\nHere's binding example. Imagine we have defined a type in scylla like this:\n\n```cql\nCREATE TYPE IF NOT EXISTS test (\n    id int,\n    name text\n);\n```\n\nNow we need to define a model for it in python.\n\n```python\nfrom dataclasses import dataclass\nfrom scyllapy.extra_types import ScyllaPyUDT\n\n@dataclass\nclass TestUDT(ScyllaPyUDT):\n    # Always define fields in the same order as in scylla.\n    # Otherwise you will get an error, or wrong data.\n    id: int\n    name: str\n\nasync def execute(scylla: Scylla) -> None:\n    await scylla.execute(\n        \"INSERT INTO table(id, udt_col) VALUES (?, ?)\",\n        [1, TestUDT(id=1, name=\"test\")],\n    )\n\n```\n\nWe also support pydantic based models. Decalre them like this:\n\n```python\nfrom pydantic import BaseModel\nfrom scyllapy.extra_types import ScyllaPyUDT\n\n\nclass TestUDT(BaseModel, ScyllaPyUDT):\n    # Always define fields in the same order as in scylla.\n    # Otherwise you will get an error, or wrong data.\n    id: int\n    name: str\n\n```\n\n# Query building\n\nScyllaPy gives you ability to build queries,\ninstead of working with raw cql. The main advantage that it's harder to make syntax error,\nwhile creating queries.\n\nBase classes for Query building can be found in `scyllapy.query_builder`.\n\nUsage example:\n\n```python\nfrom scyllapy import Scylla\nfrom scyllapy.query_builder import Insert, Select, Update, Delete\n\n\nasync def main(scylla: Scylla):\n    await scylla.execute(\"CREATE TABLE users(id INT PRIMARY KEY, name TEXT)\")\n\n    user_id = 1\n\n    # We create a user with id and name.\n    await Insert(\"users\").set(\"id\", user_id).set(\n        \"name\", \"user\"\n    ).if_not_exists().execute(scylla)\n\n    # We update it's name to be user2\n    await Update(\"users\").set(\"name\", \"user2\").where(\"id = ?\", [user_id]).execute(\n        scylla\n    )\n\n    # We select all users with id = user_id;\n    res = await Select(\"users\").where(\"id = ?\", [user_id]).execute(scylla)\n    # Verify that it's correct.\n    assert res.first() == {\"id\": 1, \"name\": \"user2\"}\n\n    # We delete our user.\n    await Delete(\"users\").where(\"id = ?\", [user_id]).if_exists().execute(scylla)\n\n    res = await Select(\"users\").where(\"id = ?\", [user_id]).execute(scylla)\n\n    # Verify that user is deleted.\n    assert not res.all()\n\n    await scylla.execute(\"DROP TABLE users\")\n\n```\n\nAlso, you can pass built queries into InlineBatches. You cannot use queries built with query_builder module with default batches. This constraint is exists, because we\nneed to use values from within your queries and should ignore all parameters passed in\n`batch` method of scylla.\n\nHere's batch usage example.\n\n```python\nfrom scyllapy import Scylla, InlineBatch\nfrom scyllapy.query_builder import Insert\n\n\nasync def execute_batch(scylla: Scylla) -> None:\n    batch = InlineBatch()\n    for i in range(10):\n        Insert(\"users\").set(\"id\", i).set(\"name\", \"test\").add_to_batch(batch)\n    await scylla.batch(batch)\n\n```\n\n## Paging\n\nQueries that were built with QueryBuilder also support paged returns.\nBut it supported only for select, because update, delete and insert should\nnot return anything and it makes no sense implementing it.\nTo make built `Select` query return paginated iterator, add paged parameter in execute method.\n\n```python\n    rows = await Select(\"test\").execute(scylla, paged=True)\n    async for row in rows:\n        print(row['id'])\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Async scylla driver for python",
    "version": "1.3.1",
    "project_urls": null,
    "split_keywords": [
        "scylla",
        " cassandra",
        " async-driver",
        " scylla-driver"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3225338cd635c201f58799836e9e88700f1a562df1ab9c5b41a2c1ce8a8416ad",
                "md5": "9d15e74c50fcea9e316b37222bbefb35",
                "sha256": "fb5daa54a70c5021170d16d26aae415a265c6913854e3742758712341946ce32"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "9d15e74c50fcea9e316b37222bbefb35",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 2955946,
            "upload_time": "2024-04-20T09:46:05",
            "upload_time_iso_8601": "2024-04-20T09:46:05.884674Z",
            "url": "https://files.pythonhosted.org/packages/32/25/338cd635c201f58799836e9e88700f1a562df1ab9c5b41a2c1ce8a8416ad/scyllapy-1.3.1-cp38-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1c4063e1c2449c7b5b604c7fb5163a48f734e2923ff1d976b69fbadcf7aefb52",
                "md5": "989f6e26eecaa839a34a5db98623a592",
                "sha256": "a7b9b18eade9d9511c5579ad8b1397a8771ee7040dcdfb5b3f66cd37725b61f3"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "989f6e26eecaa839a34a5db98623a592",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3185566,
            "upload_time": "2024-04-20T09:46:08",
            "upload_time_iso_8601": "2024-04-20T09:46:08.455214Z",
            "url": "https://files.pythonhosted.org/packages/1c/40/63e1c2449c7b5b604c7fb5163a48f734e2923ff1d976b69fbadcf7aefb52/scyllapy-1.3.1-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d9394a35cd9e6a19bfd95f603a7caa8638573235956892bf479b597cb84d928a",
                "md5": "f84019c9a417ea656926fee1ff916d65",
                "sha256": "2de9d10713246e70743077ddbfc8f52e1498c5972c90c1ff10fdd1b74ddc2fd0"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "f84019c9a417ea656926fee1ff916d65",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3815711,
            "upload_time": "2024-04-20T09:46:10",
            "upload_time_iso_8601": "2024-04-20T09:46:10.270570Z",
            "url": "https://files.pythonhosted.org/packages/d9/39/4a35cd9e6a19bfd95f603a7caa8638573235956892bf479b597cb84d928a/scyllapy-1.3.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cd37f10e96143e76cf2927868dfdbdda3bea9ec73b7d52383db68ea7456f2def",
                "md5": "e1c4ef5f772061177a5f9ab2867a38ae",
                "sha256": "0401a917ef86b6eb225b08c05360cec373052df2c0374b2ea7f256324d4aa549"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl",
            "has_sig": false,
            "md5_digest": "e1c4ef5f772061177a5f9ab2867a38ae",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3272520,
            "upload_time": "2024-04-20T09:46:12",
            "upload_time_iso_8601": "2024-04-20T09:46:12.422475Z",
            "url": "https://files.pythonhosted.org/packages/cd/37/f10e96143e76cf2927868dfdbdda3bea9ec73b7d52383db68ea7456f2def/scyllapy-1.3.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b6f9119cb60c088d27cbf5327a8445b3a1781a23852f7320414fc5df3eb7e0c7",
                "md5": "da8e38e3b4ac0289b243467b1db1a90b",
                "sha256": "4c72b53bce42098ab30a1498219d545f57f7f96be6c9d678466e70d8bd5256a7"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "da8e38e3b4ac0289b243467b1db1a90b",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3585388,
            "upload_time": "2024-04-20T09:46:14",
            "upload_time_iso_8601": "2024-04-20T09:46:14.786605Z",
            "url": "https://files.pythonhosted.org/packages/b6/f9/119cb60c088d27cbf5327a8445b3a1781a23852f7320414fc5df3eb7e0c7/scyllapy-1.3.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5d8044380e0b3836200380e39346b38186d54a16d06418a96c14e3024b4cae52",
                "md5": "61383c040a508e9ca9e08859b1a28ef6",
                "sha256": "5752d5b8ab3b2eaad82ec3142cd7ac70153280612266a2f68beb6b26d3919600"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
            "has_sig": false,
            "md5_digest": "61383c040a508e9ca9e08859b1a28ef6",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3477894,
            "upload_time": "2024-04-20T09:46:17",
            "upload_time_iso_8601": "2024-04-20T09:46:17.174558Z",
            "url": "https://files.pythonhosted.org/packages/5d/80/44380e0b3836200380e39346b38186d54a16d06418a96c14e3024b4cae52/scyllapy-1.3.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "51de7c56271162f883263dfa2142af9559f25767226b390abffe6b89f041a3ec",
                "md5": "40d7406eb36c14199c2934dc552ac3d8",
                "sha256": "e0833aca04dd248d81d2392c397cccdd6d8578d90d6d6d970aa9c12415198a53"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "40d7406eb36c14199c2934dc552ac3d8",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3647726,
            "upload_time": "2024-04-20T09:46:18",
            "upload_time_iso_8601": "2024-04-20T09:46:18.878954Z",
            "url": "https://files.pythonhosted.org/packages/51/de/7c56271162f883263dfa2142af9559f25767226b390abffe6b89f041a3ec/scyllapy-1.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "336c244450192c888d81c01244964748165db07ef9daf45c0307b0ce10925260",
                "md5": "d8b6483bad19f2f0323860c857f343d1",
                "sha256": "27dbbcb8e8757fefb74b1195f5f46987c2892309c24e0851566ed93023333dd3"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-musllinux_1_2_i686.whl",
            "has_sig": false,
            "md5_digest": "d8b6483bad19f2f0323860c857f343d1",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3700900,
            "upload_time": "2024-04-20T09:46:22",
            "upload_time_iso_8601": "2024-04-20T09:46:22.139835Z",
            "url": "https://files.pythonhosted.org/packages/33/6c/244450192c888d81c01244964748165db07ef9daf45c0307b0ce10925260/scyllapy-1.3.1-cp38-abi3-musllinux_1_2_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "38528a269a6d41dfbfdb687571cc65e02880451f2232803a6c395aeb71bd065e",
                "md5": "d8fc8b3dcf12af9c0083b8bf2effd9cb",
                "sha256": "722ac9ad8b3395b5d67c4b1b8d32f81fdf7256308dc1696604c095233261028a"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-musllinux_1_2_x86_64.whl",
            "has_sig": false,
            "md5_digest": "d8fc8b3dcf12af9c0083b8bf2effd9cb",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 3783872,
            "upload_time": "2024-04-20T09:46:24",
            "upload_time_iso_8601": "2024-04-20T09:46:24.235972Z",
            "url": "https://files.pythonhosted.org/packages/38/52/8a269a6d41dfbfdb687571cc65e02880451f2232803a6c395aeb71bd065e/scyllapy-1.3.1-cp38-abi3-musllinux_1_2_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6b1387be6129bdbfd246e925739229f008ef48b5b6b6bcde7bda5a4afc0afa31",
                "md5": "401755f50e188901abe4ee530b81ee39",
                "sha256": "ea3064b1f78e422b0f87428209de5f7c974145b9a9dfc0a8a1bc02966903301b"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-win32.whl",
            "has_sig": false,
            "md5_digest": "401755f50e188901abe4ee530b81ee39",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 2149325,
            "upload_time": "2024-04-20T09:46:26",
            "upload_time_iso_8601": "2024-04-20T09:46:26.056607Z",
            "url": "https://files.pythonhosted.org/packages/6b/13/87be6129bdbfd246e925739229f008ef48b5b6b6bcde7bda5a4afc0afa31/scyllapy-1.3.1-cp38-abi3-win32.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "26b44523e5c9b5f060b0f3ba9438dd268e0b2bf8f3c6c51e8d3c152b296263dd",
                "md5": "074af86ce1a5a9e8a3bb834e0ae30604",
                "sha256": "d63b52d09fc9d89f9c016dd3b858e1be1a6977a9596976bb4ef5f93574a41740"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "074af86ce1a5a9e8a3bb834e0ae30604",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4,>=3.8",
            "size": 2409089,
            "upload_time": "2024-04-20T09:46:28",
            "upload_time_iso_8601": "2024-04-20T09:46:28.639349Z",
            "url": "https://files.pythonhosted.org/packages/26/b4/4523e5c9b5f060b0f3ba9438dd268e0b2bf8f3c6c51e8d3c152b296263dd/scyllapy-1.3.1-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b82cf45fe7eb1255590ec00c8b99b73b612aabec42d9adb609e1ad4f00b718ff",
                "md5": "a62050eb978b0170f2c9dfa99972d186",
                "sha256": "83713681371425bc77c13cd82066aa94b10aca90638b298ae66da2369e13f311"
            },
            "downloads": -1,
            "filename": "scyllapy-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a62050eb978b0170f2c9dfa99972d186",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8",
            "size": 57879,
            "upload_time": "2024-04-20T09:46:30",
            "upload_time_iso_8601": "2024-04-20T09:46:30.022730Z",
            "url": "https://files.pythonhosted.org/packages/b8/2c/f45fe7eb1255590ec00c8b99b73b612aabec42d9adb609e1ad4f00b718ff/scyllapy-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-20 09:46:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "scyllapy"
}
        
Elapsed time: 0.21521s