summaryrefslogtreecommitdiff
path: root/python-flask-restless-client.spec
blob: d42c088718b6650b51cada7bff1ca07a8eef5043 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
%global _empty_manifest_terminate_build 0
Name:		python-flask-restless-client
Version:	0.4.13
Release:	1
Summary:	CRUD/RPC client over flask-restless
License:	MIT License
URL:		https://github.com/maarten-dp/flask-restless-client
Source0:	https://mirrors.aliyun.com/pypi/web/packages/df/11/925b8fd115c06ab74e1320a1b6175dc15c61d6e1068d9cca4f916c8d0bc8/flask-restless-client-0.4.13.tar.gz
BuildArch:	noarch

Requires:	python3-cereal-lazer
Requires:	python3-crayons
Requires:	python3-dateutils
Requires:	python3-ordered-set
Requires:	python3-packaging
Requires:	python3-pbr
Requires:	python3-prettytable
Requires:	python3-requests

%description
# flask-restless-client

[![Build Status](https://travis-ci.com/maarten-dp/flask-restless-client.svg?branch=master)](https://travis-ci.com/maarten-dp/flask-restless-client)
[![Codecov](https://codecov.io/gh/maarten-dp/flask-restless-client/branch/master/graph/badge.svg)](https://codecov.io/gh/maarten-dp/flask-restless-client)
[![PyPI](https://badge.fury.io/py/flask-restless-client.svg)](https://pypi.python.org/pypi/flask-restless-client/)

## Intoduction

The flask-restless-client is the second part of a two part library. The first being the [flask-restless-datamodel](https://github.com/maarten-dp/flask-restless-datamodel/tree/master). Together with the flask-restless-datamodel, this library serves as a goal to provide a CRUD/RPC client for Flask/SQLAlchemy applications, over HTTP using flask-restless.

Taking advantage of the easy integration offered by [Flask-Restless](https://github.com/jfinkels/flask-restless) to expose a REST CRUD interface over HTTP, this library uses its power to provide a dynamic python client. Reading the data format generated by the flask-restless-datamodel, the restless-client is able to build itself and provide you with objects that aim to mirror an SQLAlchemy-like interface on the client side.

This includes RPC possibilities to run object methods of the SQLA models defined server-side. Some setup is required to achieve a smooth interaction with the RPC part of this library.

The developer will be required to:
- write serializers from and to python natives to transfer complex objects to the server
- overwrite authentication method if the chosen authentication method is not supported by this library.

As such, it's advised to use this library as a base for a custom client for your application.
Most likely, it will be a thin layer on top of the flask-restless-client setting up some configuration.


## Installation

``` bash
    pip install flask-restless-client
```

## Setting up the client

### Exposing your model server side

The first step is to enable the flask-restless-datamodel on the server side.
You can visit [flask-restless-datamodel](https://github.com/maarten-dp/flask-restless-datamodel/tree/master) to see how to do this.

### Authenticating

As this library is intented to be useable out of the box, some built in authentication is provided.
Current out of the box authentication types are Bearer and Basic Authentication.

By default, the client will use the Bearer session, but the Basic Authentication session is importable from `restless_client.ext.auth`.

You are also able to give your own (pre-authenticated) session as a parameter when initializing the client.

Environment variables can be set to speed up authentication setup. Using the prefix `RESTLESS_CLIENT_` you can set anything involving authentication, including setting which type of session to use.

### (De)Serialization of complex objects

Part of supporting an RPC-like client is making sure the objects arrive at their destination in the same way they are sent from the source. We all know deserialisation isn't always true to what you initially put in. Therefore you can register your own (de)serializer for complex objects.

```python
from cereal_lazer import register_class
import pandas as pd

register_class(
    'DataFrame', # Register the object as this name
    pd.DataFrame, # Register the class
    lambda x: x.to_json(), # Register a serializer
    lambda x: pd.read_json(x) # Register a deserializer
)
```

These objects are registered in a global context using the `cereal_lazer` library. The client is then using the library to (de)serialize.

## Using the client


It's important tot re-iterate on the fact that this is a self-building client. That means the way you interract with this client depends on external input.
To have a practical example, consider the following SQLA models defined server-side:

```python
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)
    birth_date = db.Column(db.Date)

class Computer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)
    vendor = db.Column(db.Unicode)
    purchase_time = db.Column(db.DateTime)
    owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
    owner = db.relationship(
        'Person', backref=db.backref('computers', lazy='dynamic'))
    owner_name = association_proxy('owner', 'name')
    peers = association_proxy('owner', 'computers')
```

Based on these models, flask-restless-datamodel will generate the input for the client to build itself, allowing for an SQLA-like interface.

if we hook up our client to our server app, we'll be able to do all neat kinds of stuff

### C is for Crayon

Now that we have some server side models exposed, the models will be available on the client side and we can jump right in and create some objects.

```python
from restless_client import Client

c = Client(url='http://localhost:5000/api')
maurice = c.Person(name='Maurice')
roy = c.Person(name='Roy')

beast = c.Computer(name='TheBeast', vendor='Pear', owner=maurice)
server = c.Computer(name='Server', vendor='Pingu', owner=maurice)
pc = c.Computer(name='pc', vendor='Doors', owner=roy)

# Save objects on the server
c.save()

# Alternatively, you can save on a per-instance basis
beast.save()
```
Note that if we disregard the `c.save()` statement, and run `beast.save()` instead, that the `maurice` instance is a dependency of `beast.owner` and will be unsaved at the time we call `beast.save()`.
The client should be able to resolve these unsaved dependencies and will save them first

### R is for Rainbow

Loading objects can be done in serveral ways. The object models have a `query` attribute that is accessible to perform all read operations

#### Getting all instances from a given class

```python
everyone = c.Person.query.all()
```

#### Getting an instance based on the id

```python
maurice = c.Person.query.get(1)
```

#### Shorthand for all/get

Due to `all` and `get` being often used methods, they have been enabled with a shorthand on the object model itself

```python
everyone = c.Person.all()
maurice = c.Person.get(1)
```

#### Filtering

```python
maurice = c.Person.query.filter(c.Person.name == 'Maurice')
maurice = c.Person.query.filter_by(name='Maurice')
# limit the results to 3
some_people = c.Person.query.limit(3).all()
# offset results, ignoring the first 2
some_people = c.Person.query.offset(2).all()
# order by name
everyone = c.Person.query.order_by(name='asc').all()
# get the first instance
maurice = c.Person.query.first()
# get the last instance
maurice = c.Person.query.last()
# expect only one result
maurice = c.Person.query.one()
# expect only one result, or no result
maurice = c.Person.query.one_or_none()

# filtering over relations, get all people that own a computer with Pear vendor
maurice = c.Person.query.filter(c.Person.computers.has_(c.Computer.vendor == 'Pear'))
```

### U is for you and me

Updating is just as easy as creating objects. The library is built in a way that it flags dirty attributes, and only sends the necessary data to the server.

```python
cmptr = c.Computer.query.one()
cmptr.vendor = 'Robot'
cmptr.save()
```


### D is for ... delete

```python
cmptr = c.Computer.query.one()
cmptr.delete()
```

Note that executing `delete` is instant, and calling the save is not needed.

## Running remote object methods

As promised, this library provides an RPC-like feature that allows you to run the methods defined on your SQLA models. It's nearly nowhere as advanced as other RPCs out there, but it at least provides a way to emulate the interaction on models as if you were working with them on a server context.

The sending and receiving of complex objects does require some setup, but once this is done, doing remote method calls should run smoothly. (Although there are plenty of scenarios where remote execution might fail).

Anyway here's wonderwall

On the server we would define a model with the following method
```python
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)

    def speak(self, what_to_say):
        return "Errr... uh... ehm... {}?".format(what_to_say)
```

Which we can then remotely run by doing
```python
maurice = c.Person.query.filter(c.Person.name == 'Maurice')
print(maurice.speak("I'd rather send an email"))
```

### Future plans for running remote methods

Currently the client will crash if it tries to (de)serialize a complex object that is not yet registered.
Going forward, it would be desired to apply a "no-crash" policy. The idea behind this is that the data is there, and it's not because (de)serialization failed, that the program should halt execution.

If a (de)serializer was not registered for a complex object, one will be emulated from the data available. Accessing data that is known to it will allow you to interact with it without issue, accessing functions or data that is unknown to the emulated object will result in an exception.





%package -n python3-flask-restless-client
Summary:	CRUD/RPC client over flask-restless
Provides:	python-flask-restless-client
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-flask-restless-client
# flask-restless-client

[![Build Status](https://travis-ci.com/maarten-dp/flask-restless-client.svg?branch=master)](https://travis-ci.com/maarten-dp/flask-restless-client)
[![Codecov](https://codecov.io/gh/maarten-dp/flask-restless-client/branch/master/graph/badge.svg)](https://codecov.io/gh/maarten-dp/flask-restless-client)
[![PyPI](https://badge.fury.io/py/flask-restless-client.svg)](https://pypi.python.org/pypi/flask-restless-client/)

## Intoduction

The flask-restless-client is the second part of a two part library. The first being the [flask-restless-datamodel](https://github.com/maarten-dp/flask-restless-datamodel/tree/master). Together with the flask-restless-datamodel, this library serves as a goal to provide a CRUD/RPC client for Flask/SQLAlchemy applications, over HTTP using flask-restless.

Taking advantage of the easy integration offered by [Flask-Restless](https://github.com/jfinkels/flask-restless) to expose a REST CRUD interface over HTTP, this library uses its power to provide a dynamic python client. Reading the data format generated by the flask-restless-datamodel, the restless-client is able to build itself and provide you with objects that aim to mirror an SQLAlchemy-like interface on the client side.

This includes RPC possibilities to run object methods of the SQLA models defined server-side. Some setup is required to achieve a smooth interaction with the RPC part of this library.

The developer will be required to:
- write serializers from and to python natives to transfer complex objects to the server
- overwrite authentication method if the chosen authentication method is not supported by this library.

As such, it's advised to use this library as a base for a custom client for your application.
Most likely, it will be a thin layer on top of the flask-restless-client setting up some configuration.


## Installation

``` bash
    pip install flask-restless-client
```

## Setting up the client

### Exposing your model server side

The first step is to enable the flask-restless-datamodel on the server side.
You can visit [flask-restless-datamodel](https://github.com/maarten-dp/flask-restless-datamodel/tree/master) to see how to do this.

### Authenticating

As this library is intented to be useable out of the box, some built in authentication is provided.
Current out of the box authentication types are Bearer and Basic Authentication.

By default, the client will use the Bearer session, but the Basic Authentication session is importable from `restless_client.ext.auth`.

You are also able to give your own (pre-authenticated) session as a parameter when initializing the client.

Environment variables can be set to speed up authentication setup. Using the prefix `RESTLESS_CLIENT_` you can set anything involving authentication, including setting which type of session to use.

### (De)Serialization of complex objects

Part of supporting an RPC-like client is making sure the objects arrive at their destination in the same way they are sent from the source. We all know deserialisation isn't always true to what you initially put in. Therefore you can register your own (de)serializer for complex objects.

```python
from cereal_lazer import register_class
import pandas as pd

register_class(
    'DataFrame', # Register the object as this name
    pd.DataFrame, # Register the class
    lambda x: x.to_json(), # Register a serializer
    lambda x: pd.read_json(x) # Register a deserializer
)
```

These objects are registered in a global context using the `cereal_lazer` library. The client is then using the library to (de)serialize.

## Using the client


It's important tot re-iterate on the fact that this is a self-building client. That means the way you interract with this client depends on external input.
To have a practical example, consider the following SQLA models defined server-side:

```python
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)
    birth_date = db.Column(db.Date)

class Computer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)
    vendor = db.Column(db.Unicode)
    purchase_time = db.Column(db.DateTime)
    owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
    owner = db.relationship(
        'Person', backref=db.backref('computers', lazy='dynamic'))
    owner_name = association_proxy('owner', 'name')
    peers = association_proxy('owner', 'computers')
```

Based on these models, flask-restless-datamodel will generate the input for the client to build itself, allowing for an SQLA-like interface.

if we hook up our client to our server app, we'll be able to do all neat kinds of stuff

### C is for Crayon

Now that we have some server side models exposed, the models will be available on the client side and we can jump right in and create some objects.

```python
from restless_client import Client

c = Client(url='http://localhost:5000/api')
maurice = c.Person(name='Maurice')
roy = c.Person(name='Roy')

beast = c.Computer(name='TheBeast', vendor='Pear', owner=maurice)
server = c.Computer(name='Server', vendor='Pingu', owner=maurice)
pc = c.Computer(name='pc', vendor='Doors', owner=roy)

# Save objects on the server
c.save()

# Alternatively, you can save on a per-instance basis
beast.save()
```
Note that if we disregard the `c.save()` statement, and run `beast.save()` instead, that the `maurice` instance is a dependency of `beast.owner` and will be unsaved at the time we call `beast.save()`.
The client should be able to resolve these unsaved dependencies and will save them first

### R is for Rainbow

Loading objects can be done in serveral ways. The object models have a `query` attribute that is accessible to perform all read operations

#### Getting all instances from a given class

```python
everyone = c.Person.query.all()
```

#### Getting an instance based on the id

```python
maurice = c.Person.query.get(1)
```

#### Shorthand for all/get

Due to `all` and `get` being often used methods, they have been enabled with a shorthand on the object model itself

```python
everyone = c.Person.all()
maurice = c.Person.get(1)
```

#### Filtering

```python
maurice = c.Person.query.filter(c.Person.name == 'Maurice')
maurice = c.Person.query.filter_by(name='Maurice')
# limit the results to 3
some_people = c.Person.query.limit(3).all()
# offset results, ignoring the first 2
some_people = c.Person.query.offset(2).all()
# order by name
everyone = c.Person.query.order_by(name='asc').all()
# get the first instance
maurice = c.Person.query.first()
# get the last instance
maurice = c.Person.query.last()
# expect only one result
maurice = c.Person.query.one()
# expect only one result, or no result
maurice = c.Person.query.one_or_none()

# filtering over relations, get all people that own a computer with Pear vendor
maurice = c.Person.query.filter(c.Person.computers.has_(c.Computer.vendor == 'Pear'))
```

### U is for you and me

Updating is just as easy as creating objects. The library is built in a way that it flags dirty attributes, and only sends the necessary data to the server.

```python
cmptr = c.Computer.query.one()
cmptr.vendor = 'Robot'
cmptr.save()
```


### D is for ... delete

```python
cmptr = c.Computer.query.one()
cmptr.delete()
```

Note that executing `delete` is instant, and calling the save is not needed.

## Running remote object methods

As promised, this library provides an RPC-like feature that allows you to run the methods defined on your SQLA models. It's nearly nowhere as advanced as other RPCs out there, but it at least provides a way to emulate the interaction on models as if you were working with them on a server context.

The sending and receiving of complex objects does require some setup, but once this is done, doing remote method calls should run smoothly. (Although there are plenty of scenarios where remote execution might fail).

Anyway here's wonderwall

On the server we would define a model with the following method
```python
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)

    def speak(self, what_to_say):
        return "Errr... uh... ehm... {}?".format(what_to_say)
```

Which we can then remotely run by doing
```python
maurice = c.Person.query.filter(c.Person.name == 'Maurice')
print(maurice.speak("I'd rather send an email"))
```

### Future plans for running remote methods

Currently the client will crash if it tries to (de)serialize a complex object that is not yet registered.
Going forward, it would be desired to apply a "no-crash" policy. The idea behind this is that the data is there, and it's not because (de)serialization failed, that the program should halt execution.

If a (de)serializer was not registered for a complex object, one will be emulated from the data available. Accessing data that is known to it will allow you to interact with it without issue, accessing functions or data that is unknown to the emulated object will result in an exception.





%package help
Summary:	Development documents and examples for flask-restless-client
Provides:	python3-flask-restless-client-doc
%description help
# flask-restless-client

[![Build Status](https://travis-ci.com/maarten-dp/flask-restless-client.svg?branch=master)](https://travis-ci.com/maarten-dp/flask-restless-client)
[![Codecov](https://codecov.io/gh/maarten-dp/flask-restless-client/branch/master/graph/badge.svg)](https://codecov.io/gh/maarten-dp/flask-restless-client)
[![PyPI](https://badge.fury.io/py/flask-restless-client.svg)](https://pypi.python.org/pypi/flask-restless-client/)

## Intoduction

The flask-restless-client is the second part of a two part library. The first being the [flask-restless-datamodel](https://github.com/maarten-dp/flask-restless-datamodel/tree/master). Together with the flask-restless-datamodel, this library serves as a goal to provide a CRUD/RPC client for Flask/SQLAlchemy applications, over HTTP using flask-restless.

Taking advantage of the easy integration offered by [Flask-Restless](https://github.com/jfinkels/flask-restless) to expose a REST CRUD interface over HTTP, this library uses its power to provide a dynamic python client. Reading the data format generated by the flask-restless-datamodel, the restless-client is able to build itself and provide you with objects that aim to mirror an SQLAlchemy-like interface on the client side.

This includes RPC possibilities to run object methods of the SQLA models defined server-side. Some setup is required to achieve a smooth interaction with the RPC part of this library.

The developer will be required to:
- write serializers from and to python natives to transfer complex objects to the server
- overwrite authentication method if the chosen authentication method is not supported by this library.

As such, it's advised to use this library as a base for a custom client for your application.
Most likely, it will be a thin layer on top of the flask-restless-client setting up some configuration.


## Installation

``` bash
    pip install flask-restless-client
```

## Setting up the client

### Exposing your model server side

The first step is to enable the flask-restless-datamodel on the server side.
You can visit [flask-restless-datamodel](https://github.com/maarten-dp/flask-restless-datamodel/tree/master) to see how to do this.

### Authenticating

As this library is intented to be useable out of the box, some built in authentication is provided.
Current out of the box authentication types are Bearer and Basic Authentication.

By default, the client will use the Bearer session, but the Basic Authentication session is importable from `restless_client.ext.auth`.

You are also able to give your own (pre-authenticated) session as a parameter when initializing the client.

Environment variables can be set to speed up authentication setup. Using the prefix `RESTLESS_CLIENT_` you can set anything involving authentication, including setting which type of session to use.

### (De)Serialization of complex objects

Part of supporting an RPC-like client is making sure the objects arrive at their destination in the same way they are sent from the source. We all know deserialisation isn't always true to what you initially put in. Therefore you can register your own (de)serializer for complex objects.

```python
from cereal_lazer import register_class
import pandas as pd

register_class(
    'DataFrame', # Register the object as this name
    pd.DataFrame, # Register the class
    lambda x: x.to_json(), # Register a serializer
    lambda x: pd.read_json(x) # Register a deserializer
)
```

These objects are registered in a global context using the `cereal_lazer` library. The client is then using the library to (de)serialize.

## Using the client


It's important tot re-iterate on the fact that this is a self-building client. That means the way you interract with this client depends on external input.
To have a practical example, consider the following SQLA models defined server-side:

```python
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)
    birth_date = db.Column(db.Date)

class Computer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)
    vendor = db.Column(db.Unicode)
    purchase_time = db.Column(db.DateTime)
    owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
    owner = db.relationship(
        'Person', backref=db.backref('computers', lazy='dynamic'))
    owner_name = association_proxy('owner', 'name')
    peers = association_proxy('owner', 'computers')
```

Based on these models, flask-restless-datamodel will generate the input for the client to build itself, allowing for an SQLA-like interface.

if we hook up our client to our server app, we'll be able to do all neat kinds of stuff

### C is for Crayon

Now that we have some server side models exposed, the models will be available on the client side and we can jump right in and create some objects.

```python
from restless_client import Client

c = Client(url='http://localhost:5000/api')
maurice = c.Person(name='Maurice')
roy = c.Person(name='Roy')

beast = c.Computer(name='TheBeast', vendor='Pear', owner=maurice)
server = c.Computer(name='Server', vendor='Pingu', owner=maurice)
pc = c.Computer(name='pc', vendor='Doors', owner=roy)

# Save objects on the server
c.save()

# Alternatively, you can save on a per-instance basis
beast.save()
```
Note that if we disregard the `c.save()` statement, and run `beast.save()` instead, that the `maurice` instance is a dependency of `beast.owner` and will be unsaved at the time we call `beast.save()`.
The client should be able to resolve these unsaved dependencies and will save them first

### R is for Rainbow

Loading objects can be done in serveral ways. The object models have a `query` attribute that is accessible to perform all read operations

#### Getting all instances from a given class

```python
everyone = c.Person.query.all()
```

#### Getting an instance based on the id

```python
maurice = c.Person.query.get(1)
```

#### Shorthand for all/get

Due to `all` and `get` being often used methods, they have been enabled with a shorthand on the object model itself

```python
everyone = c.Person.all()
maurice = c.Person.get(1)
```

#### Filtering

```python
maurice = c.Person.query.filter(c.Person.name == 'Maurice')
maurice = c.Person.query.filter_by(name='Maurice')
# limit the results to 3
some_people = c.Person.query.limit(3).all()
# offset results, ignoring the first 2
some_people = c.Person.query.offset(2).all()
# order by name
everyone = c.Person.query.order_by(name='asc').all()
# get the first instance
maurice = c.Person.query.first()
# get the last instance
maurice = c.Person.query.last()
# expect only one result
maurice = c.Person.query.one()
# expect only one result, or no result
maurice = c.Person.query.one_or_none()

# filtering over relations, get all people that own a computer with Pear vendor
maurice = c.Person.query.filter(c.Person.computers.has_(c.Computer.vendor == 'Pear'))
```

### U is for you and me

Updating is just as easy as creating objects. The library is built in a way that it flags dirty attributes, and only sends the necessary data to the server.

```python
cmptr = c.Computer.query.one()
cmptr.vendor = 'Robot'
cmptr.save()
```


### D is for ... delete

```python
cmptr = c.Computer.query.one()
cmptr.delete()
```

Note that executing `delete` is instant, and calling the save is not needed.

## Running remote object methods

As promised, this library provides an RPC-like feature that allows you to run the methods defined on your SQLA models. It's nearly nowhere as advanced as other RPCs out there, but it at least provides a way to emulate the interaction on models as if you were working with them on a server context.

The sending and receiving of complex objects does require some setup, but once this is done, doing remote method calls should run smoothly. (Although there are plenty of scenarios where remote execution might fail).

Anyway here's wonderwall

On the server we would define a model with the following method
```python
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode, unique=True)

    def speak(self, what_to_say):
        return "Errr... uh... ehm... {}?".format(what_to_say)
```

Which we can then remotely run by doing
```python
maurice = c.Person.query.filter(c.Person.name == 'Maurice')
print(maurice.speak("I'd rather send an email"))
```

### Future plans for running remote methods

Currently the client will crash if it tries to (de)serialize a complex object that is not yet registered.
Going forward, it would be desired to apply a "no-crash" policy. The idea behind this is that the data is there, and it's not because (de)serialization failed, that the program should halt execution.

If a (de)serializer was not registered for a complex object, one will be emulated from the data available. Accessing data that is known to it will allow you to interact with it without issue, accessing functions or data that is unknown to the emulated object will result in an exception.





%prep
%autosetup -n flask-restless-client-0.4.13

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-flask-restless-client -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.4.13-1
- Package Spec generated