Skip to main content

A little language for schema-enforced models.

Project description

Fame is a framework for metamodelling in Python.

  • Entities are described by models

  • Models are described by metamodels

  • Models have fields, derived fields and constraints

  • Entities can have custom fields

  • Entities can be created even if data is invalid

  • There are functions to validate and get error messages

  • Validation checks presence and type of fields

  • Validation checks all constraints

  • Derived fields are memoized

Example

class Experiment(Model):

    @schema
    def metamodel(self, m):
        m.field('name', str)
        m.field('subject', options(
            'user',
            'visitor',
            'email',
            'listing',
            'market'
        ))
        m.field('treatments', array(str))
        m.field('percent_exposed', int, default=100)
        m.field('design', nullable(regexp('^https?')))

    @derived_field
    def is_miscellanous(self):
        return self.subject not in ['user', 'visitor']

    @constraint("expected percent_exposed to not exceed 100, got {}")
    def constraint(self):
        if self.percent_exposed > 100:
            return self.percent_exposed

Conventions

  • Define metamodel function first

  • Then define derived field functions

  • Then define all the constraint functions

  • Constraint functions are all named “constraint”, that is intentional

Installation

To install this package, run

pip install fame

Contributing

Bug reports and pull requests are welcome on github at, https://github.com/akuhn/py-fame

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

fame-1.2.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file fame-1.2.0.tar.gz.

File metadata

  • Download URL: fame-1.2.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.4.2 requests/2.9.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.10

File hashes

Hashes for fame-1.2.0.tar.gz
Algorithm Hash digest
SHA256 54a8f05afc7b0e9356eb8b91744e6f5c02e4e55e72438a2de6c8b42444eea26c
MD5 bc162b208b98537e74c4cda4e552e4c2
BLAKE2b-256 9f74e38c0d85a729266e87a903ddb4f759d60a1b97d14c2add32a756cf301068

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