Small and expressive ORM to interact with Google Datastore inspired by Django, Mongo-Engine and Peewee
Project description
No SeiQueLa ORM
IN DEVELOPMENT
No SeiQueLa is a small and expressive ORM (Object Relational Mapper) to interact with Google Datastore inspired by Django, Mongo-Engine and Peewee.
Requirements
- Google Cloud credentials
- Python>=3.8
Installing
The library can be installed using pip:
pip install noseiquela_orm
Usage
Creating model classes:
from noseiquela_orm.entity import Model
from noseiquela_orm.key import Key, ParentKey
from noseiquela_orm import properties
class Customer(Model):
name = properties.StringProperty(required=True)
age = properties.IntegerProperty(required=True)
is_deleted = properties.BooleanProperty(default=False, required=True)
class CustomerAddress(Model):
__kind__ = "Address"
__parent__ = properties.ParentKey(Customer, required=True)
number = properties.IntegerProperty(required=True)
address_one = properties.StringProperty(required=True)
address_two = properties.StringProperty()
is_default = properties.BooleanProperty(required=True)
is_deleted = properties.BooleanProperty(default=False, required=True)
In case the project name, namespace (or any other parameter of the google.cloud.datastore.Client
) needs to be changed, simply create a Meta
class inside the template with the desired information.
class Product(Model):
quantity = properties.IntegerProperty(required=True)
name = properties.StringProperty(required=True)
value = properties.FloatProperty(required=True)
class Meta:
namespace = "production"
project = "products"
Adding new entities:
new_customer = Customer(
name="Geraldo Castro",
age=29,
)
new_customer.save()
new_address = CustomerAddress(
parent_id=new_customer.id,
number=199,
address_one="Some St.",
is_default=True
)
new_address.save()
Query on database:
customer = Customer.query.filter(name="Geraldo Castro").first()
customer_address = Customer.query.filter(parend_id=customer.id)
less_than_or_eq_29 = Customer.query.filter(age__le=29) # age <= 29
more_than_30 = Customer.query.filter(age__gt=30) # age > 30
all_customers = [
customer.to_dict()
for customer in Customer.query.all()
]
Authentication
The library uses the standard way of authenticating Google libraries (google-auth-library-python).
The search for credentials happens in the following order:
-
If the environment variable
GOOGLE_APPLICATION_CREDENTIALS
is set to a valid service account path. -
If the
Google Cloud SDK
is installed and has the credentials of the application to be used, these will be loaded. -
If the application is running in the
App Engine standard environment
(first generation), then the credentials and project ID are taken from theApp Identity Service
. -
If the application is running in
Compute Engine
,Cloud Run
,App Engine flexible environment
orApp Engine standard environment
(second generation), then the credentials and project ID are taken from theMetadata Service
.
More details at this link.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for noseiquela_orm-0.0.8.dev1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44790ca203fc2026933cab63bf833ac3b1ea27376f3e2dae8fcbdf30cc8b4f7c |
|
MD5 | 52435c658a687c7c3837e5822fa4408d |
|
BLAKE2b-256 | 04175a1f7cf4b5b3af5c4f01c5c7d9a95b565a84ce2f97aa3fafb9ed29fe7305 |
Hashes for noseiquela_orm-0.0.8.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0469f59c61e98c858da72254a08b25f7c33b884652273def2689d49c9e4b782a |
|
MD5 | b1a2ee9cdbb87abd441740d1959b5b57 |
|
BLAKE2b-256 | c4ed8cc478def9b22de3e2ef89a42b4c255e6d8db747d931983d3350380dba28 |