Skip to main content

Dict schema helper for schema-free projects

Project description

Morpheus [![Build Status](https://travis-ci.org/ziadsawalha/morpheus.png)](https://travis-ci.org/ziadsawalha/morpheus) [![Coverage Status](https://coveralls.io/repos/ziadsawalha/morpheus/badge.png?branch=master)](https://coveralls.io/r/ziadsawalha/morpheus)
========

Morpheus helps you define schemas for your dict-based classes and perform validation, migration, and generate documentation. It tries to make this normally unfun task painless and easy.

### Design Goals ###

**Readable.** Like a docstring at the top of your class definition, a schema definition should be readable and understandable.

**Transparent.** You know how to work with dicts. You should be able to keep using dicts. And you should be able to import morpheus or leave it out and your code should still work.

**Flexible.** You get to pick which backend you use (sqlalchemy, sqlite, NoSQL, etc...), so morpheus operates on native python dicts and doesn't touch your data store.

### Features ###

* Intuitive schema definition using pythonic idioms
* Optional schema validation and inspection controlled globally or per class
* Automatic or on-demand migration from an older schema to the current one
* Generates schema documentation for developers and users
* DRY definition of schemas. Do it once. Do it in one place. Use it anywhere (docs, data store, and code)
* Zero dependencies required
* Enable/disable it with a single line
* Passes all python tests for a dict (including json and pickle serialization)
* Painless, pain-free, simple and easy!

### Install ###

```bash
$ pip install morpheus
```

### Usage ###

Here is a simple example of a schema definition on a dict-based class.

```python
# Let's import MorpheusDict as dict in our module
from morpheus import MorpheusDict as dict
# Note: Comment this last line out to completely disable morpheus. No code
# changes needed.


#
# Let's limit the keys allowed on our dict-based class by adding a __schema__
# entry
#
class Foo(dict):
__schema__ = ['id', 'name', 'state']

#
# Now let's make sure this really works
#
try:
Foo(sneaky='git blame someone for this!')
except AttributeError as exc:
print "Thank you, Morpheus! You caught an error: %s" % exc

# Prints:
#
# Thank you, Morpheus! You caught an error: 'sneaky' is not a permitted
# attribute for a 'Foo'
#
```


### Contributing ###

Ziad Sawalha (ziadsawalha) is the creator and current maintainer of Morpheus. Pull requests are always welcome.

Before submitting a pull request, please ensure you have added/updated the appropriate tests (and that all existing tests still pass with your changes), and that your coding style follows PEP 8 and doesn't cause pyflakes to complain.


### Legal ###

Copyright 2013 by Ziad Sawalha.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the 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

morpheus-0.0.2.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file morpheus-0.0.2.tar.gz.

File metadata

  • Download URL: morpheus-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for morpheus-0.0.2.tar.gz
Algorithm Hash digest
SHA256 504986be05057fcc8f28caa03d633f5084a753cad29bb489b7d622656930ba6c
MD5 fbd97b43075899e2394566dea80b95d0
BLAKE2b-256 8936dd01e0292421194c530ae47c1b88e9a7f1f37843de13a45de74b581c3951

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page