Skip to main content
Python versions Build status Coverage Version status Documentation Status

Anyblok Pyramid Rest Api

The main idea is to provide facilities for building restful api that interacts with AnyBlok models through a CRUD like pattern.

As dependecy, it use Cornice for its validators and schema abilities and Marshmallow for schema definition, serialization and deserialization (we have since split this work to AnyBlok_Marshmallow).

Features

  • Incoming request validation through schema (validation before database query and ability to validate several parts of the request object)

  • CRUD queries always with request.validated data

  • Data deserialization for response through schema

  • Easy CRUD resource declaration (map a model on an endpoint)

  • Automatic schema generation based on models introspection

  • Advanced collection filtering, ordering, paging (querystring validation through schema)

Todo

  • Helpers for JsonSchema or Swagger

  • Advanced introspection for api documentation generation

Request lifecyle

incoming request

-> validators -> deserializer (json to dict) -> schema load -> request.validated -> request.errors

request.validated

-> crud -> resulting records
-> deserializer (records to schema dump)
-> serializer (default pyramid / cornice dict to json serializer)
-> response

Author

Franck Bret

Contributors

Jean-Sébastien Suzanne

Credits

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file,You can obtain one at http://mozilla.org/MPL/2.0/.

Copyright (c) 2017, Franck Bret

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

0.7.0 (2020-12-07)

  • Added entries in the querystring:

    • primary-keys[key1:key2:…:keyn]=va1:va2:…:van,vb1:vb2:…:vbn

    • ~primary-keys[key1:key2:…:keyn]=va1:va2:…:van,vb1:vb2:…:vbn

    • composite-filter[key1:key2:…:keyn][op1:op2:…:opn]=va1:va2:…:van,vb1:vb2:…:vbn

    • ~composite-filter[key1:key2:…:keyn][op1:op2:…:opn]=va1:va2:…:van,vb1:vb2:…:vbn

0.6.0 (2020-05-15)

Added

  • CrudResource can now allow calls to certain http verb without being logged.

    * allow_unauthenticated_user_to_access_to_all_verbs
    * allow_unauthenticated_user_to_access_to_collection_get
    * allow_unauthenticated_user_to_access_to_collection_post
    * allow_unauthenticated_user_to_access_to_collection_patch
    * allow_unauthenticated_user_to_access_to_collection_put
    * allow_unauthenticated_user_to_access_to_collection_delete
    * allow_unauthenticated_user_to_access_to_get
    * allow_unauthenticated_user_to_access_to_delete
    * allow_unauthenticated_user_to_access_to_patch
    * allow_unauthenticated_user_to_access_to_put

Refactored

  • Updated the order_by[operator]=fieldname by order_by[fieldname]=operator because more than one order by can be send

0.5.0 (2019-06-21)

Refactored

  • Tag can now be grouped

    @Adapter.tags('green', 'blue')
    def tag_is_green_or_blue(self, querystring, query, tags):
        query = query.join(self.registry.Customer.tags, aliased=True)
        query = query.filter(self.registry.Tag.name.in_(tags))
        return query
  • adapter_cls is renamed QueryStringAdapter. the compatibility is keeped and a DeprecationWarning is sent

0.4.0 (2019-01-03)

Added

  • CrudResource.execute(name, kwarg) decorator to define Service on:

    • collection_path/execute/name: validator on the body

    • path/execute/name: validator on the path and the body

    @resource(collection_path='/foo', path='/foo/{bar}')
    class MyResource(CrudResource):
        @CrudResource.service('print', collection=True)
        def plop(self):  # /foo/execute/print
            # verb : POST (default), GET, PUT, PATCH, DELETE, ...
            # schema optional
            # query = self.get_querystring('rest action given to get_model')
            # body = self.body
            ...
    
        @CrudResource.service('print')
        def otherplop(self):  # /foo/{bar}/execute/print
            # verb : POST (default), GET, PUT, PATCH, DELETE, ...
            # schema optional for body, pathschema for path
            # body = self.body
            ...
  • Collection views to update and delete collection defined by querystring:

    • collection_put

    • collection_patch

    • collection_delete

Refactored

  • If a request.error is found during the execution of a view in the crud resource, then a registry.rollback will be done

  • Collection post is waiting a list of dict, Now it is possible to create more than one entry

0.3.0 (2018-12-07)

Removed

  • Compatibility with python 3.3

Fixed

  • QueryString filters and tags are executed only one time by query

  • in the context manager to save the error, the registry is now rollbacked

Refactored

  • The error field is now the key of the errors description dict (All validation errors messages are now dict)

0.2.1 (2018-10-06)

Added

  • MANIFEST.in file

Removed

  • VERSION file

0.2.0 (2018-10-01)

Added

  • context key in querystring. The goal is to add some informations to help custom filter and tag to build their query

Refactored

  • Now the querystring desarializer use regex to get the informations

0.1.0 (2018-09-26)

Added

  • CRUDResource class to define REST api

  • service behaviours

Metadata

Release files for anyblok_pyramid_rest_api 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anyblok_pyramid_rest_api 0.7.0
File Size Uploaded
anyblok_pyramid_rest_api-0.7.0.tar.gz 41.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anyblok_pyramid_rest_api 0.7.0
File Interpreter ABI Platform
anyblok_pyramid_rest_api-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 109.7 kB

Release files / anyblok_pyramid_rest_api-0.7.0.tar.gz

Download URL anyblok_pyramid_rest_api-0.7.0.tar.gz
Size 41.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f68c616f0b4274e57e400e894909eb1078b098f74a0724834f4279456ab00c3d
BLAKE2b-256 checksum
How to use checksums
0e43536816bd18cc8988d18347d5f104cad562e58955bacf42f8a189267eea6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release files / anyblok_pyramid_rest_api-0.7.0-py3-none-any.whl

Download URL anyblok_pyramid_rest_api-0.7.0-py3-none-any.whl
Size 68.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffc71f5491cc2f67e0cb9496418d1f25bc2c5834598516a667f66bea6c2c1940
BLAKE2b-256 checksum
How to use checksums
399ca38623609fa4ae7bd18821219f609dc9dab47f050a7a618feecf187d135a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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