Skip to main content

Swamper is a simple interface to clean input data and turn this data into objects.

Project description

Build Status

Swamper is here for you to simplify cleaning input data and building python objects from this data.

Status

Currently actively used and watched.

Usage

Requirements

  • python 2.7

  • python 3.3

  • python 3.4

  • python 3.5

Installation

Installation can be done from github or PyPI.

Running

models.py

# Pretend this is some model.
class Company(object):
    # name = fields.Str(ascii_only=True)
    # github_address = fields.Str()

    def __init__(self, **kwargs):
        self.__dict__ = kwargs

validate.py

import unicodedata

from swamper.base import BaseSwamper


class CompanySwamper(BaseSwamper):
    fields = [
        'name',
        'github_address',
    ]

    def __init__(self, data):
        super(CompanySwamper, self).__init__(self.fields, data)

    def clean_name(self, name, is_blank):
        if is_blank or len(name.strip()) == 0:
            raise ValueError('Field "name" is required.')

        # Keep only ascii characters.
        return unicodedata.normalize('NFKD', name).encode('ascii', 'ignore')

    def clean_github_address(self, address, is_blank):
        if is_blank or len(address.strip()) == 0:
            raise ValueError('Field "github_address" cannot be empty.')

        return 'https://github.com/%s' % address

app.py

from .models import Company
from .validate import CompanySwamper


data = {
    'name': u'Devhouse Spindl\xe9',
    'github_address': 'wearespindle',
}
swamper = CompanySwamper(data)
assert swamper.is_clean()
company = swamper.build_or_update(Company, ['name', 'github_address'])

assert company.name == 'Devhouse Spindle'
assert company.github_address == 'https://github.com/wearespindle'

Contributing

See the CONTRIBUTING.md file on how to contribute to this project.

Contributors

See the CONTRIBUTORS.md file for a list of contributors to the project.

Roadmap

Changelog

The changelog can be found in the CHANGELOG.md file.

In progress

  • Nothing at the moment

Future

  • Nothing planned at the moment

Get in touch with a developer

If you want to report an issue see the CONTRIBUTING.md file for more info.

We will be happy to answer your other questions at opensource@wearespindle.com

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

swamper-0.1.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file swamper-0.1.tar.gz.

File metadata

  • Download URL: swamper-0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for swamper-0.1.tar.gz
Algorithm Hash digest
SHA256 19f594936d10e53a2a9b81d533695a0816f93c026375b56e383baf225e43d481
MD5 1511584980f6c3821462dcda0cbf1115
BLAKE2b-256 c9156f386ad995faeed6b0e5d2bc03da0b44546d03f0f708992f7c469b08a7fd

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