Skip to main content

PyPI latest CI Status

Resource centered REST API clients

Ideas on how to use

Not all features stated in the following examples are implemented. This section serves only as motivation for future functionalities.

import resources


class PersonResource(resources.Resource):
    class Meta:
        base_endpoint = 'http://api.com/v1/persons/'


class PageResource(resources.Resource):
    class Meta:
        endpoints = {
            'delete': 'http://api.com/v1/pages/{}/'
            'filter': 'http://api.com/v1/pages/'
            'get': 'http://api.com/v1/pages/{}/'
            'patch': 'http://api.com/v1/pages/{}/'
            'post': 'http://api.com/v1/pages/'
            'put': 'http://api.com/v1/pages/'
        }

    owner = resources.RelatedField(
        PersonResource,
        source_field='owner_url',  # default is owner_id
        auto_follow=True,  # default is False
    )

    comments = resources.MultipleRelatedField(
        CommentResource,
        source_field='comments_url',
    )


# GET / single
person = Person.objects.get(pk=1)
print(person.name)

# GET / list
person_reqset = Person.objects.filter(age=18)
for person in person_reqset:  # lazy request
    print(person.name)

# POST
person = Person.objects.create(name='John Doe', age=18)

# PATCH
person.age = 20
person.save()

# PUT
person = Person.objects.update_or_create(name='John Doe', age=30)

Metadata

Release files for resources 0.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 resources 0.0.1
File Size Uploaded
resources-0.0.1.tar.gz 3.7 kB Details

Release files / resources-0.0.1.tar.gz

Download URL resources-0.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
02547fbca96492b4a9e0a39c83bc922b8ed8f2969ee9909ceedf3609821eb900
BLAKE2b-256 checksum
How to use checksums
0d9892a43ff6fb8773590ef1edf21383a0b089a8eb0a6f18c5c2d93a8a49b864
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.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