Skip to main content

Plugin for Scruby - In search methods, returns results in the form of dictionaries.

Project description

Logo

scruby-return-dict

Plugin for Scruby - In search methods, returns results in the form of dictionaries.

Build Status Docs PyPI pyversions PyPI status PyPI version fury.io
Types: Pyrefly Code style: Ruff Format PyPI Downloads GitHub license

Scruby-Return-Dict is a plugin for the Scruby project.


Documentation

Requirements

Installation

uv add scruby-return-dict

Usage

Examples

import anyio
from typing import Any
from pydantic import Field
from scruby import Scruby, ScrubyModel, ScrubySettings
from scruby_return_dict import ReturnDict
from pprint import pprint as pp

# Plugins connection.
ScrubySettings.plugins = [
    ReturnDict,
]


class Car(ScrubyModel):
    """Car model."""

    brand: str = Field(strict=True, frozen=True)
    model: str = Field(strict=True, frozen=True)
    year: int = Field(strict=True, frozen=True)
    power_reserve: int = Field(strict=True, frozen=True)
    description: str = Field(strict=True)
    # key is always at bottom
    key: str = Field(
        strict=True,
        frozen=True,
        default_factory=lambda data: f"{data['brand']}:{data['model']}",
    )


async def main() -> None:
    """Example."""
    # Delete unnecessary tables that remain due to errors
    await FullTextSearch.delete_orphaned_tables()

    # Get collection `Car`
    car_coll = await Scruby.collection(Car)
    # Create cars.
    for num in range(1, 10):
        car = Car(
            brand="Mazda",
            model=f"EZ-6 {num}",
            year=2025,
            power_reserve=600,
            description="Electric cars are the future of the global automotive industry.",
        )
        await car_coll.add_doc(car)

    # Find one car
    car_dict: dict[str, Any] | None = await car_coll.plugins.returnDict.find_one(c
        filter_fn=lambda doc: doc.brand == "Mazda" and doc.model == "EZ-6 9",
    )
    if car_dict is not None:
      pp(car_dict)
    else:
      print("Not Found")

    # Fand many cars
    car_list: list[dict[str, Any]] | None = await car_coll.plugins.returnDict.find_many(
        filter_fn=lambda doc: doc.brand == "Mazda",
    )
    if car_list is not None:
      pp(car_list)
    else:
      print("Not Found")

    # Full database deletion.
    # Hint: The main purpose is tests.
    Scruby.napalm()


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

Changelog

GPL-3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scruby_return_dict-0.2.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file scruby_return_dict-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: scruby_return_dict-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"42","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for scruby_return_dict-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2aadc64ae3bf71e518e6cef7b1e6befe98983b4494381d32150a85e9fb302f62
MD5 e06acf1bb1f5d3a2299753a0e9b86ea2
BLAKE2b-256 cadd7f4fc1c7b3b8a8fee3b04f10a91b30aaeeb535c04f3dd7d5307b410beb0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page