
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Writing a decoupled application -- a "pluggable app" -- in Python is a common practice.
Looking for a modern registry that scales from simple use, up to rich dependency injection (DI)?
hopscotch
is a registry and DI package for Python 3.9+, written to support research into component-driven development for Python's web story.
I expect a lot of skepticism.
In fact, I don't expect a lot of adoption.
Instead, I'm using this to learn and write articles.
viewdom
, everything is wired up and you can just work in templates.Hopscotch takes its history from wired
, which came from Pyramid
, which came from Zope
.
You can install Hopscotch
via pip from PyPI:
$ pip install hopscotch
Let's look at: a hello world, same but with a decorator, replacement, and multiple choice.
Here's a registry with one "kind of thing" in it:
# One kind of thing
@dataclass
class Greeter:
"""A simple greeter."""
greeting: str = "Hello!"
registry = Registry()
registry.register(Greeter)
# Later
greeter = registry.get(Greeter)
# greeter.greeting == "Hello!"
That's manual registration -- let's try with a decorator:
@injectable()
@dataclass
class Greeter:
"""A simple greeter."""
greeting: str = "Hello!"
registry = Registry()
registry.scan()
# Later
greeter = registry.get(Greeter)
# greeter.greeting == "Hello!"
You're building a pluggable app where people can replace builtins:
# Some site might want to change a built-in.
@injectable(kind=Greeter)
@dataclass
class CustomGreeter:
"""Provide a different ``Greeter`` in this site."""
greeting: str = "Howdy!"
Sometimes you want a Greeter
but sometimes you want a FrenchGreeter
-- for example, based on the row of data a request is processing:
@injectable(kind=Greeter, context=FrenchCustomer)
@dataclass
class FrenchGreeter:
"""Provide a different ``Greeter`` in this site."""
greeting: str = "Bonjour!"
# Much later
child_registry = Registry(
parent=parent_registry,
context=french_customer
)
greeter2 = child_registry.get(Greeter)
# greeter2.greeting == "Bonjour!"
Finally, have your data constructed for you in rich ways, including custom field "operators":
@injectable()
@dataclass
class SiteConfig:
punctuation: str = "!"
@injectable()
@dataclass
class Greeter:
"""A simple greeter."""
punctuation: str = get(SiteConfig, attr="punctuation")
greeting: str = "Hello"
def greet(self) -> str:
"""Provide a greeting."""
return f"{self.greeting}{self.punctuation}"
The full code for these examples are in the docs, with more explanation (and many more examples.)
And don't worry, dataclasses aren't required.
Some support is available for plain-old classes, NamedTuple
, and even functions.
Contributions are very welcome. To learn more, see the contributor's guide.
Distributed under the terms of the MIT license, Hopscotch is free and open source software.
If you encounter any problems, please file an issue along with a detailed description.
This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.
FAQs
Type-oriented registry with dependency injection.
We found that hopscotch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.