Skip to main content

This package helps defining and creating small and reusable components that can serve as guard or validation methods.

Example

Below is an example of a validation on a content item.

from dataclasses import dataclass
from prejudice.errors import ConstraintError
from prejudice.validators import Or


@dataclass
class Document:
    id: str
    body: str = ''
    content_type: str = 'text/plain'


def non_empty_document(item):
    """Implementation of a validator/predicate
    """
    if not item.body:
        raise ConstraintError('Body is empty.')


class ContentType:

    def __init__(self, content_type):
        self.ct = content_type

    def __call__(self, item):
        if item.content_type != self.ct:
            raise ConstraintError(
                f'Expected {self.ct}, got {item.content_type}.')


  validator = Or((
      ContentType('text/plain'),
      Or((ContentType('text/html'), non_empty_document))
  ))
  document = Document(id='test', content_type='application/json')
  validator(document)  # raises ConstraintsErrors

CHANGES

0.1.1 (2023-11-09)

  • Cython update and included py3.11

0.1 (2022-03-16)

  • Initial release.

Metadata

Release files for prejudice 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prejudice 0.1.1
File Size Uploaded Provenance Actions
prejudice-0.1.1.tar.gz 125.8 kB Without provenance Details for prejudice-0.1.1.tar.gz

Release files / prejudice-0.1.1.tar.gz

Download URL prejudice-0.1.1.tar.gz
Size 125.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2a2538f80c6d9d2820123abcf5782a26987afb46db69f1f76fa56c190b5555b2
BLAKE2b-256 checksum
How to use checksums
428df7c5dc50e0d097674e1c9b4c9192bb7e6702808407dad9ad0cdb00aab783
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

Security for prejudice 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page