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

uv add scruby-plugin

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 Any
from pydantic import Field
from scruby import Scruby, ScrubyModel, ScrubyConfig
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()


# Plugins connection.
ScrubyConfig.plugins = [
    CollectionMeta,
]


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

    brand: str = Field(strict=True, frozen=True)
    model: str = Field(strict=True, frozen=True)
    year: int = Field(strict=True)
    power_reserve: int = 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:
    # Get collection `Car`.
    car_coll = await Scruby.collection(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-0.6.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scruby_plugin-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d07702111f098edf1ccbfb2a026f22fcf53bdb3b94255c03c0cb147bd8b661b5
MD5 195a288c27e551784312f7edbe51274f
BLAKE2b-256 385f84f7038e75f8aae5de4396d4aa6aa0ecc37341d8fb2a81735d7c2b1646b3

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