Skip to main content

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

Release files for swamper 0.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 swamper 0.1
File Size Uploaded
swamper-0.1.tar.gz 5.1 kB Details

Release files / swamper-0.1.tar.gz

Download URL swamper-0.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
19f594936d10e53a2a9b81d533695a0816f93c026375b56e383baf225e43d481
BLAKE2b-256 checksum
How to use checksums
c9156f386ad995faeed6b0e5d2bc03da0b44546d03f0f708992f7c469b08a7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file

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