Metadata-Version: 2.3
Name: fastastra
Version: 0.1.35
Summary: 
Author: seb
Author-email: seb@datastax.com
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: astra-assistants (>=2.5.3,<3.0.0)
Requires-Dist: cassandra-driver (>=3.28,<4.0)
Requires-Dist: loguru (>=0.7.0,<0.8.0)
Requires-Dist: numpy (>=1.24.2,<2.0.0)
Requires-Dist: pydantic (>=2.7.4,<3.0.0)
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
Requires-Dist: python-fasthtml (>=0.2.4,<0.3.0)
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
Requires-Dist: tenacity (>=8.2.1,<9.0.0)
Requires-Dist: uvicorn (>=0.30.3,<0.31.0)
Description-Content-Type: text/markdown

# fastastra

[![commits](https://img.shields.io/github/commit-activity/m/phact/fastastra)](https://github.com/phact/fastastra/commits/main)
[![Github Last Commit](https://img.shields.io/github/last-commit/phact/fastastra)](https://github.com/phact/fastastra/commits/main)
[![PyPI version](https://badge.fury.io/py/fastastra.svg)](https://badge.fury.io/py/fastastra)
[![Discord chat](https://img.shields.io/static/v1?label=Chat%20on&message=Discord&color=blue&logo=Discord&style=flat-square)](https://discord.gg/MEFVXUvsuy)
[![Stars](https://img.shields.io/github/stars/phact/fastastra?style=social)](https://github.com/phact/fastastra/stargazers)

fastastra is modeled after [fastlite](https://github.com/AnswerDotAI/fastlite) and it allows you to use [FastHTML](https://github.com/AnswerDotAI/fasthtml) with AstraDB (Cassandra). 

## Installation

    poetry add fastastra

or 

    pip install fastastra


## To connect:

    from fastastra.fastastra import AstraDatabase
    db = AstraDatabase(token, dbid) # get your token and dbid from https://astra.datastax.com

## Basic usage

### List tables
    db.t
    
### Create a table
    cats = db.t.cats
    if cats not in db.t:
        cats.create(cat_id=uuid.uuid1, name=str, partition_keys='cat_id')


### Insert a row
    cat_timeuuid = uuid.uuid1()
    cats.update(cat_id=cat_timeuuid, name="fluffy")

### List all rows
    rows = cats()

### ANN / vector search
    db = AstraDatabase(token, dbid, embedding_model="embed-english-v3.0") # supports all embedding models in LiteLLM using env vars
    dogs = db.t.dogs
    if dogs not in db.t:
        #dogs.create(id=int, name=str, good_boy=bool, embedding=(list[float], 2), pk='id') # specify dimensions in create
        dogs.create(id=int, name=str, good_boy=bool, embedding=list[float], pk='id') # infer dimensions from db.embedding_model
        dogs.c.good_boy.index()
        dogs.c.embedding.index()

    dogs.insert(id=2, good_boy=True, name="spike", embedding=[0.1, 0.2])

    index_lookukp = dogs.xtra(good_boy=True)
    ann_matches = dogs.xtra(embedding=[0.2, 0.2])

### Get dataclass and pydantic model
    dataclass = cats.dataclass()
    model = cats.pydantic_model()

### Get a row
    print(cats[cat_timeuuid])

# Delete a row
    cats.delete(cat_timeuuid)

 or

    cats.delete(str(cat_timeuuid))


## Run a FastHTML example:

This example was taken almost verbatim from [the FastHTML examples repo](https://github.com/AnswerDotAI/fasthtml-example). The only change was the dependency, the db connection string, and changing the id from `int` to `uuid1`.

    poetry install

    poetry run python examples/todo.py

