Plugin for Scruby - In search methods, returns results in the form of dictionaries.
Project description
scruby-return-json
Plugin for Scruby - In search methods, returns result as json strings.
scruby-return-json is a plugin for the Scruby project.
Installation
uv add scruby-return-json
Usage
import anyio
from typing import Any
from pydantic import Field
from scruby import Scruby, ScrubyModel, ScrubySettings
from scruby_return_json import ReturnJson
# Plugins connection.
ScrubySettings.plugins = [
ReturnJson,
]
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."""
# 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_json: str | None = await car_coll.plugins.returnJson.find_one(c
filter_fn=lambda doc: doc.brand == "Mazda" and doc.model == "EZ-6 9",
)
if car_json is not None:
print(car_json)
else:
print("Not Found")
# Fand many cars
car_json_list: list[str] | None = await car_coll.plugins.returnJson.find_many(
filter_fn=lambda doc: doc.brand == "Mazda",
)
if car_json_list is not None:
print(car_json_list)
else:
print("Not Found")
# Full database deletion.
# Hint: The main purpose is tests.
Scruby.napalm()
if __name__ == "__main__":
anyio.run(main)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scruby_return_json-0.2.7-py3-none-any.whl.
File metadata
- Download URL: scruby_return_json-0.2.7-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33a62aa4a5fb4107c39261c3ba3429df9d4615a8f8edec6064d942d0d34259a6
|
|
| MD5 |
c361ec1d5e58e2dd3906c96f3beac59f
|
|
| BLAKE2b-256 |
e3457327085936f62174f8f21cd257b9b52c532b672603328892c46b0728c5e8
|