pyramid_skue
pyramid_skue is a library for builidn REST API services on top of Pyramid framework.
Installation
Requires Pyramid >= 1.5a2
Install with pip:
pip install pyramid_skue
or using easy_install:
easy_install pyramid_skue
Usage
Create api python package inside your main project package.
Populate api/resourses.py with the defenition of resource:
from pyramid_skue.rest.api import ResourceDescription
from pyramid_skue.rest.api import HttpMethodDescription
from pyramid_skue.rest.api import HttpParameterDescription
from pyramid_skue.http import CommonResponse
from pyramid_skue.rest.resources import DocumentResource
from .response import MessageResourceJson
class MessageResource(DocumentResource):
"""Represents resource for readin/creating messages."""
# Resource definition
def describe_resource(self):
"""Self description.
"""
description = 'Author of the message'
author_param = HttpParameterDescription(
'author', 'string', is_required=True,
description=description)
description = 'Title of the message'
title_param = HttpParameterDescription(
'title', 'string', is_required=True,
description=description)
description = 'Title of the message (optional)'
title_optional_param = HttpParameterDescription(
'title', 'string', is_required=False,
description=description)
description = 'Message body'
body_param = HttpParameterDescription(
'body', 'string', is_required=True,
description=description)
description = "Get existing messages"
get_method = HttpMethodDescription(
'GET', parameters=[title_optional_param],
description=description)
description = "Post message"
post_method = HttpMethodDescription(
'POST', parameters=[author_param, title_param, body_param],
description=description)
description = "Create/Get messages"
resource = ResourceDescription(
'MessageResource', url="/api/message",
methods=[get_method, post_method],
description=description)
return resource
def read_resource(self):
"""
Return messages. Can be filtered by title.
Assuming that ``storage`` is some database you're using.
"""
title = self.payload.get('title')
if title:
messages = storage.filter(title).all()
else:
messages = storage.all()
body = MessageResourceJson(messages)
return CommonResponse.success(body)
def create_resource(self):
"""Create message.
``storage`` is some hypothetical database.
"""
author = self.payload.get('author')
title = self.payload.get('title')
body = self.payload.get('body')
message_id = storage.create_message(author=author, title=title, body=body)
resource_uri = self.get_resoruce_uri(message_id)
return CommonResponse.resource_created(resource_uri)
Then add api/response.py:
from pyramid_skue.json.utils import ResourceJSONRepresentation
class MessageResourceJson(ResourceJSONRepresentation):
"""Represents a JSON response for MessageResource."""
def __init__(self, messages):
ResourceJSONRepresentation.__init__(self, 'MessageResource')
self.objects = []
for message in messages:
self.objects.append({
'author': message.author,
'title': message.title,
'body': message.body})
Now register the views in your __init__.py:
config.add_route('api-message', '/api/message')
config.add_view('your_app.api.resources.MessageResource',
route_name='api-message',
renderer='string',
permission='view', # whatever permission you like
check_csrf=True)
It’s better to secure your views agains CSRF attacs, look at the pyramid’s documentation.
Contacts
The project is maintained by Cyril Panshine (@CyrilPanshine). Bug reports and pull requests are very much welcomed!
0.1.0
Initial version
Metadata
Release files for pyramid_skue 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyramid_skue-0.1.0.tar.gz | 13.4 kB | Without provenance | Details |
Release files / pyramid_skue-0.1.0.tar.gz
| Download URL | pyramid_skue-0.1.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6e80d05cef2f668e621ffa880b62f7d1aa8d2ac602dc9ce0c6b657ff5320e8a
|
|
BLAKE2b-256 checksum How to use checksums |
db30056e08c2bf7bf416f959d1468e26db4bf6cc9d95bf94512e8de97ceb3c60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pyramid_skue 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.