Skip to main content
NoSQL Rest Preprocessor
=======================
[![Build Status](https://travis-ci.org/felixbr/nosql-rest-preprocessor.svg?branch=master)](https://travis-ci.org/felixbr/nosql-rest-preprocessor)
[![Coverage Status](https://img.shields.io/coveralls/felixbr/nosql-rest-preprocessor.svg)](https://coveralls.io/r/felixbr/nosql-rest-preprocessor)

A middleware module which solves common problems when building rest-apis with nosql databases.

### Installation

```
pip install nosql-rest-preprocessor
```

### Examples

```python
from nosql-rest-preprocessor.models import BaseModel

class AddressModel(BaseModel):
required_attributes = {'street', 'city', 'plz'}

# if you specify optional attributes explicitely, it will
# not allow anything but these and the required ones
optional_attributes = {'location'}

class UserModel(BaseModel):
required_attributes = {'firstName', 'lastName', 'email'}
immutable_attributes = {'id'}
private_attributes = {'password', 'salt'}

# will use AddressModel to validate, merge and prepare the content of the 'address' attribute
sub_models: {
'address': AddressModel
}
```

```python
new_user_from_request = {
"firstName": "Sepp",
"lastName": "Huber",
"email": "sepp.huber@fancepants.com",
"address": {
"street": "Bakerstreet 1",
"city": "London",
"plz": "12345"
}
}

# checks required_attributes and raises ValidationError if something's amiss
UserModel.validate(new_user_from_request)

```

```python
user_obj_from_db = db.fetch_user_by_email("sepp.huber@fancepants.com")

# strips out any non-public attributes
response_obj = UserModel.prepare_response(user_obj_from_db)

return Response(response_obj)
```

```python
from nosql-rest-preprocessor.models import BaseModel
from nosql-rest-preprocessor.resolvers import resolve, ResolveWith

class AddressModel(BaseModel):
...

class UserModel(BaseModel):
...

resolved_attributes = {
'address' = ResolveWith(lookup_func=SomeDB.find_address_by_key, model=AddressModel)
}

...

user = {
"name": "cookie_m0nster",
"address": "foreign_key_for_address"
}

resolved_obj = resolve(UserModel, user)
# resolved_obj['address'] is now replaced by the dict fetched by SomeDB.find_address_by_key('foreign_key_for_address')
```

### Running tests
```
pip install detox

detox
```

Metadata

Release files for nosql-rest-preprocessor 0.3

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

Source distribution (sdist)

Source distribution for nosql-rest-preprocessor 0.3
File Size Uploaded Provenance Actions
nosql-rest-preprocessor-0.3.zip 8.4 kB Without provenance Details for nosql-rest-preprocessor-0.3.zip

Release files / nosql-rest-preprocessor-0.3.zip

Download URL nosql-rest-preprocessor-0.3.zip
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f6c5d11df70d0dee96a156c68559e4c6e7c07714ca4fefae9267cffb1cdc5417
BLAKE2b-256 checksum
How to use checksums
2fd0814d1e61464b32c3cb0c8b34c87baedfd0e83c3083050cc521507b72c0cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for nosql-rest-preprocessor 0.3

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.

Release history Release notifications | RSS feed

This release

0.3 This release

1 release file No provenance

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