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.


Currently actively used and watched.



  • python 2.7
  • python 3.3
  • python 3.4
  • python 3.5


Installation can be done from github or PyPI.


# 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

import unicodedata

from swamper.base import BaseSwamper

class CompanySwamper(BaseSwamper):
    fields = [

    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 '' % address

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 == 'Devhouse Spindle'
assert company.github_address == ''


See the file on how to contribute to this project.


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



The changelog can be found in the file.

In progress

  • Nothing at the moment


  • Nothing planned at the moment

Get in touch with a developer

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

We will be happy to answer your other questions at

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Files for swamper, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size swamper-0.1.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page