Skip to main content

Sync remote API resources to Django models

Project description

Django remote resources

Sync remote API resources to Django models

Quick start

pip install django-remote-resources

Add AbstractRemoteResource to your model (1), and define a mapping between the fields in the remote data to your model's fields (2), and create a custom QuerySet manager for the model, inheriting from RemoteResourceQuerySet and define method get_remote_data_iterator (3). Optionally define a remote_data_key_field that points to a unique identifier on the remote data (4).

class ResourceMirrorQuerySet(  # (3)
    RemoteResourceQuerySet
):
    def get_remote_data_iterator(self, *args, **kwargs):
        client = RemoteClient()
        return client.get_data(**kwargs)  # should return an iterator, with each item representing a page of data


class ResourceMirror(
    AbstractRemoteResource,  # (1)
    models.Model
):
    remote_id = models.CharField(max_length=255)
    name = models.CharField(max_length=255)
    email = models.EmailField()

    objects = ResourceMirrorQuerySet.as_manager()  # (3)

    remote_to_model_fields_map = {  # (2)
        'id': 'remote_id',
        'name': 'name',
        'email': 'email',
    }
    remote_data_key_field = 'id'  # (4)

Development and Testing

IDE Setup

Add the example directory to the PYTHONPATH in your IDE to avoid seeing import warnings in the tests modules. If you are using PyCharm, this is already set up.

Running the Tests

Install requirements

pip install -r requirements.txt

For local environment

pytest

For all supported environments

tox

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

django-remote-resources-0.1.0rc2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-remote-resources-0.1.0rc2.tar.gz.

File metadata

File hashes

Hashes for django-remote-resources-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 53430b009aa849dec2a4072bbf3ef6421ad02a7ba57a15caf5905457f6f87fb5
MD5 5b687e8d2280411b05f9dcc3a9826378
BLAKE2b-256 ce5a17bae01f91c8152d576888b5ba35d24570fe0ccee7d6d742b67194528e05

See more details on using hashes here.

File details

Details for the file django_remote_resources-0.1.0rc2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_remote_resources-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 2583735a2edebdb8076c8c43671fb8d5f64070692d49ad5a917b987df082281c
MD5 1485ef2705c160f43d2fb2663683e84a
BLAKE2b-256 3839e0f814ba97d52088b8428f0928782c396c9299e33fa3fbf5a589b9d411fc

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