Skip to main content

Stop trying to make fetch happen.

Project description

beckon

Stop trying to make fetch happen.

A typed component registry backed by zope.interface. Register components behind formal interfaces. Look them up without circular imports. Relationships are inferred and bidirectional.

Install

pip install beckon

For Django integration:

pip install beckon[django]

Quick Start

from zope.interface import Interface
from beckon import register, BeckonInterface

class _IService(Interface):
    pass

IService = BeckonInterface(_IService)
# register
register(IService, MyService, name='email')

# beckon
import beckon

beckon(IService, 'email')  # -> MyService
beckon(IService)           # -> [('email', MyService)]

The module itself is callable — import beckon; beckon(...) works without importing the function separately.

Django Integration

Add beckon.django to INSTALLED_APPS:

INSTALLED_APPS = [
    'beckon.django',
    # ...
]

This registers a name resolver for Django models (_meta.label_lower) and provides IModel:

from beckon import register
from beckon.django import IModel

from .models import Post

register(IModel, Post)
import beckon
from beckon.django import IModel

Post = beckon(IModel, 'posts.post')

Custom Interfaces with Relationships

from zope.interface import Interface
from beckon import BeckonInterface, register

class _ISerializer(Interface):
    pass

ISerializer = BeckonInterface(_ISerializer, infer_from='model')

Register a serializer and it automatically links to its model:

register(IModel, Post)
register(ISerializer, PostSerializer)  # infers from Meta.model

beckon(ISerializer, 'posts.post')  # -> PostSerializer
beckon(IModel, 'posts.post')       # -> Post (reverse works too)

Type Safety

Interfaces carry generic type information:

IModel: BeckonInterface[type[Model]] = BeckonInterface(_IModel)

mypy infers return types automatically:

beckon(IModel, 'auth.user')  # mypy sees: type[Model] | None

Define your own typed interfaces and get the same inference:

IPermission: BeckonInterface[type[BasePermission]] = BeckonInterface(_IPermission)
beckon(IPermission, 'is_admin')  # mypy sees: type[BasePermission] | None

License

BSD 2-Clause. See LICENSE.

Project details


Download files

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

Source Distribution

beckon-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

beckon-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file beckon-0.1.0.tar.gz.

File metadata

  • Download URL: beckon-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for beckon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 85fe444ad883cee33d204b197315e0a4414ada1cf7f6f4d88725325c0dfe2ca8
MD5 53a68cd700895e399f7147663fae5ca8
BLAKE2b-256 36095174ab42e14f39f98c47017d6a49547f5066c0262dfbc5024e54f1208aee

See more details on using hashes here.

Provenance

The following attestation bundles were made for beckon-0.1.0.tar.gz:

Publisher: publish.yml on LimpidTech/beckon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file beckon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: beckon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for beckon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36d003b79433c89ddb9e516178282643b593f45b244fcc4ed20b296f83cf188e
MD5 ce088f0c7305158150a6652e56eccb90
BLAKE2b-256 d3b0ac3370205798615c4ed203a23eee321ef60b91f08c3fe80bfd5dc2198c33

See more details on using hashes here.

Provenance

The following attestation bundles were made for beckon-0.1.0-py3-none-any.whl:

Publisher: publish.yml on LimpidTech/beckon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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