Skip to main content

Library for creating Scruby plugins.

Project description

Scruby-Plugin

Library for creating plugins for Scruby.



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


Requirements

Installation

# For Scruby version 0
uv add "scruby-plugin>=0.8.2,<1.0.0"
# For Scruby version 1
uv add "scruby-plugin>=1.0.0,<2.0.0"
# For Scruby version 2
uv add "scruby-plugin>=2.0.0,<3.0.0"

Usage

from typing import Any
from scruby_plugin import ScrubyPlugin

class PluginName(ScrubyPlugin):
    def __init__(self, scruby_self: Any) -> None:
        ScrubyPlugin.__init__(self, scruby_self)

    ...your code...

Example

import anyio
from typing import Annotated, Any
from pydantic import Field
from scruby import Scruby, ScrubyModel
from scruby_plugin import ScrubyPlugin
from pprint import pprint as pp


# Create plugin
class CollectionMeta(ScrubyPlugin):
    def __init__(self, scruby_self: Scruby) -> None:
        ScrubyPlugin.__init__(self, scruby_self)

    async def get(self) -> Any:
        scruby_self = self.scruby_self()
        return await scruby_self.get_meta()


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

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


async def main() -> None:
    """Example."""
    # Activate database.
    Scruby.run(plugins=[CollectionMeta])

    # Get collection `Car`.
    car_coll = Scruby(Car)
    # Get metadata of collection
    meta = await car_coll.plugins.collectionMeta.get()
    # Print to console
    pp(meta)
    #
    # Full database deletion.
    # Hint: The main purpose is tests.
    Scruby.napalm()

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

Changelog

MIT

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_plugin-2.2.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file scruby_plugin-2.2.5-py3-none-any.whl.

File metadata

  • Download URL: scruby_plugin-2.2.5-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","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_plugin-2.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5e275311b504803363175d105008693658709be73b9eb01deade2236b7b52f34
MD5 dec7a9f5e4287a7a50e47f8bf081a6b9
BLAKE2b-256 fa4755b73774055ec09c11717e08d7931adc3779bce41fe57d3fac5b62ce855a

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