Skip to main content

Google Appengine ndb Property Generator

https://travis-ci.org/taxpon/ndb_prop_gen.svg https://coveralls.io/repos/github/taxpon/ndb_prop_gen/badge.svg?branch=master

Google Appengine ndb Property Generator written in python. You can convert json data into your custom ndb property by this library.

What is this?

Simple generator of ndb Property Subclass. Using json to define the property of the class.

Source json sample

{
    "name": "book",
    "class": "Book",
    "props": [
        {
            "name": "title",
            "type": "String",
            "default": ""
        },
        {
            "name": "author",
            "type": "String",
            "default": ""
        },
        {
            "name": "published",
            "type": "DateTime",
            "default": null
        },
        {
            "name": "price",
            "type": "Float",
            "default": 10.0
        },
        {
            "name": "read",
            "type": "Bool",
            "default": false
        }
    ]
}

Generated python sample

# -*- coding: utf-8 -*-
from google.appengine.ext import ndb

__all__ = ["Book", "BookModel", "BookProperty", "LocalBookProperty"]


class Book(object):
    def __init__(self, title="", author="", published=None, price=10.0, read=False):
        self._title = title
        self._author = author
        self._published = published
        self._price = price
        self._read = read

    @property
    def title(self):
        return self._title

    @property
    def author(self):
        return self._author

    @property
    def published(self):
        return self._published

    @property
    def price(self):
        return self._price

    @property
    def read(self):
        return self._read

    def _prepare_for_put(self):
        pass

    def _has_repeated(self):
        pass

    def _to_dict(self):
        pass


class BookModel(ndb.Model):
    title = ndb.StringProperty(default="")
    author = ndb.StringProperty(default="")
    published = ndb.DateTimeProperty()
    price = ndb.FloatProperty(default=10.0)
    read = ndb.BooleanProperty(default=False)


class BookProperty(ndb.StructuredProperty):
    def __init__(self, **kwds):
        super(BookProperty, self).__init__(BookModel, **kwds)

    def _validate(self, value):
        assert isinstance(value, Book)

    def _to_base_type(self, value):
        return BookModel(
            title=value.title,
            author=value.author,
            published=value.published,
            price=value.price,
            read=value.read,
        )

    def _from_base_type(self, value):
        return Book(
            title=value.title,
            author=value.author,
            published=value.published,
            price=value.price,
            read=value.read,
        )


class LocalBookProperty(ndb.StructuredProperty):
    def __init__(self, **kwds):
        super(LocalBookProperty, self).__init__(BookModel, **kwds)

    def _validate(self, value):
        assert isinstance(value, Book)

    def _to_base_type(self, value):
        return BookModel(
            title=value.title,
            author=value.author,
            published=value.published,
            price=value.price,
            read=value.read,
        )

    def _from_base_type(self, value):
        return Book(
            title=value.title,
            author=value.author,
            published=value.published,
            price=value.price,
            read=value.read,
        )

Please see the example directory for more examples.

Usage

  1. Install ndb_prop_gen via pip

pip install ndb_prop_gen
  1. Call generate method

  • via command line

ndb_prop_gen test.json
  • via python code

import ndb_prop_gen as npg  # noqa

# filename is the json's filename
npg.generate(filename)

LICENSE

MIT

Metadata

Release files for ndb_prop_gen 0.0.4

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

Source distribution (sdist)

Source distribution for ndb_prop_gen 0.0.4
File Size Uploaded Provenance Actions
ndb_prop_gen-0.0.4.tar.gz 4.2 kB Without provenance Details for ndb_prop_gen-0.0.4.tar.gz

Release files / ndb_prop_gen-0.0.4.tar.gz

Download URL ndb_prop_gen-0.0.4.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a5657347bb296c059d977fe45df54bc3ebf3486b5a135b85255e02196407e68b
BLAKE2b-256 checksum
How to use checksums
bf8afb05cc1feb7d9d7b6bbf46fe2c00f72b4f1e5980ea8df109b5e93f986170
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ndb_prop_gen 0.0.4

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.

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