pumpwood-communication

Functions to help communicating with pumpwood based backends

https://github.com/murabei-opensource-codes/pumpwood-communication

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.0%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Functions to help communicating with pumpwood based backends

Basic Info
  • Host: GitHub
  • Owner: Murabei-OpenSource-Codes
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Size: 7.07 MB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 2
Created about 4 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License Citation

README.md

PumpWood Communication

This packages facilitates the communication with end-points with Pumpwood pattern and helps with authentication. This package was developed by Murabei Data Science and is under BSD-3-Clause license.


Pumpwood is a native brasilian tree which has a symbiotic relation with ants (Murabei)

Documentation page

Check documentation page here.

Quick start

The main class in package is PumpWoodMicroService and it abstract all end-point communication using functions. It is possible to set the credentials when initializing the object or after using the init method.

``` from pumpwood_communication.microservices import PumpWoodMicroService

microservice = PumpWoodMicroService( server_url="http://0.0.0.0:8080/", username="pumpwood", password="pumpwood") microservice.login() ```

Some times is easier to create the object and then set the credentials, this can be done using the init method ``` from pumpwood_communication.microservices import PumpWoodMicroService

microservice = PumpWoodMicroService()

After many validations or other functions

[...]

microservice.init( server_url="http://0.0.0.0:8080/", username="pumpwood", password="pumpwood") microservice.login() ```

PumpWoodMicroService constructor and init method have some basic parameters. - name: Name of the microservice (object to make communication), it is only used for debug proposes, and does not afect usage. - serverurl: URL of the server to connect using a Pumpwood pattern. - username: Username for the connection. - password: Password for the connection. - verifyssl: At sobre test enviroment the end-point may have a self assigned certificates.

Quick start

It will be explored some basic usage for the package, for more information check documentation.

Basic definition

There are some concepts that might make it ease to understand the general structure of pumpwood based end-point.

Pumpwood end-points are organized in model_class which is the class exposed thought the Pumpwood Api. Every object in Pumpwood have its own primary key, which is retrieved as pk at JSON responses indenpendetly how if is used at the database (pk may be a id or indentification_id at DB).

All end-points for a given model_class are structured with the structure rest/[model_class]/[end-point]/[?pk]&[query parameters]. Some examples below: - [POST] rest/user/list/ - [POST] rest/user/list-without-pag/ - [POST] rest/user/save/ - [GET] rest/user/retrieve/5/ - [POST] rest/company/save/ - [POST] rest/company/actions/duplicate/5/ - [GET] rest/company/actions/

Raise and error treatment

When a Pumpwood exception is identified on the request response the microservice re-raise it using the same exception. This helps debug and propagating errors on other end-points.

It is possible to use exceptions defined at PumpWood microservice at exceptions.

``` from pumpwood_communication.exceptions import PumpWoodException

raise PumpWoodException( message="Error to be mapped using the APIs", payload={ "payload": "payload-data" }) ```

Basic usage

List and list without pagination

Both methods list objects using dictionaries passed as payload on a post request.

``` from pumpwood_communication.microservices import PumpWoodMicroService

microservice = PumpWoodMicroService( server_url="http://0.0.0.0:8080/", username="pumpwood", password="pumpwood") microservice.login()

listresults = microservice.list( modelclass="Company", filterdict={ "nameicontains": "Acme", }, excludedict={ "status_in": ["deprected", "inactive"], }, orderby=["holding_name", "-name"] ) ```

Using filter_dict and exclude_dict is possible adjust the query of the objects. It is also possible to order the results using a list of fields, names starting with - will order in decrescent.

list method paginate the results acording to backend page size default. list_without_pag does not paginate and must be used with caution for a large number of objects. It is possible to paginate the results using the pks recived.

``` microservice = PumpWoodMicroService( server_url="http://0.0.0.0:8080/", username="pumpwood", password="pumpwood") microservice.login()

Get the first page results using the filters and the

order

pag1 = microservice.list( modelclass="Company", filterdict={ "nameicontains": "Acme", }, excludedict={ "status_in": ["deprected", "inactive"], }, orderby=["holding_name", "-name"] )

Get the list of the pks recived

pag1pks = [obj["pk"] for obj in pag_1]

Use in the next page query

pag2 = microservice.list( modelclass="Company", filterdict={ "nameicontains": "Acme", }, excludedict={ "statusin": ["deprected", "inactive"], "pkin": pag1pks }, orderby=["holdingname", "-name"] ) ```

If is also possible to restrict the fields returned by end-point using fields parameter, if None the default columns with be returned.

Using __ is possible to access related fields and apply operators to the request (almost equal to Django api). Some examples of operators:

Time/Date and Numeric

  • gt: Greater then.
  • lt: Less then.
  • gte: Greater then and equal.
  • lte: Less then and equal.

List of values

  • in: Check if a values is present in a list.

Text field

  • contains: Check if a value contains another.
  • icontains: Check if a value contains another, case insensitive.
  • unaccent_icontains: Se o texto contém o texto especificado desconsiderando o case e os acentos.
  • startswith: Se o texto começa com.
  • istartswith: Se o texto começa com sem considerar o case.
  • unaccent_istartswith: Se o texto começa com sem considerar o case e os acentos.
  • endswith: Se o texto termina com.
  • iendswith: Se o texto termina com e desconsiderando o case.
  • unaccent_iendswith: Se o texto termina com e desconsiderando o case e os acentos.

Campos de data e tempo:

  • year: Se a data é no ano especificado.
  • month: Se a data é no mês especificado.
  • day: Se a data é no dia especificado.

JSON Fields

It is possible to access JSON key/value using -> operator.

list_results = microservice.list( model_class="Company", filter_dict={ "json_dimensions->dim1__icontains": "test_dimention", }, exclude_dict={ "json_extra_info->parameter__in": [ 1, "1", None], }, order_by=[ "json_extra_info->company-cat", "-name"] )

Saving and updating objects

To save and update object it is possible to use the save method. It takes a dictionary with a model_class indicating the end-point that will be used.

If a pk is passed at the dictionary then the object will be updated. pk=None also lead to adding a new object to database.

```

Creating a new object

microservice.save(objdict={ "modelclass": "Company", "name": "New Company", "jsonextrainfo": { "cat": "joe" }, "jsondimensions": { "dim1": "testsave" } })

Updating a object in database

microservice.save(objdict={ "pk": 5, "modelclass": "Company", "name": "New Company", "jsonextrainfo": { "cat": "joe" }, "jsondimensions": { "dim1": "testsave" } }) ```

Actions: listing and executing

At each modelclass it is possible to associate actions, they can be regular or static (not associated with an object). For each modelclass is possible to list the available actions using list_actions functions

``` resplistactions = microservice.listactions( modelclass="Company")

[

{

"action_name": "duplicate",

"doc_string": "Doc string of the function",

"info": "Duplicate the company at the database.",

"isstaticfunction": false,

"parameters": {

"suffix": {

"default_value": "new ",

"required": false,

"type": "bool"

},

"clone_id": {

"default_value": None,

"required": true,

"type": "bool"

}

}

},

{

"actionname": "createcompanyfromholding",

"doc_string": "Doc string of the function",

"info": "Create a company associated to a holding.",

"isstaticfunction": true,

"parameters": {

"holding_name": {

"default_value": None,

"required": true,

"type": "str"

},

"parameters": {

"default_value": {},

"required": false,

"type": "dict"

}

}

}

]

```

To execute an action it is possible to use executeaction function. It execute at a modelclass.

``` microservice.executeaction( modelclass="Company", pk=1, action="duplicate", parameters={ "clone_id": True})

microservice.executeaction( modelclass="Company", action="createcompanyfromholding", parameters={ "holdingname": "Holding one", "parameters": {"parm1": 1, "param2": 2}}) ```

Other functions

It is possible to use other functions, the documentation can be gatered using the doc string. Some of the functions in microservice.

  • error_handler
  • request_post
  • request_get
  • request_delete
  • listregisteredroutes
  • listregisteredendpoints
  • list
  • listwithoutpag
  • list_dimentions
  • listdimentionvalues
  • list_one
  • retrieve
  • retrieve_file
  • retrievestreamingfile
  • save
  • savestreamingfile
  • delete
  • removefilefield
  • delete_many
  • list_actions
  • execute_action
  • search_options
  • fill_options
  • pivot
  • bulk_save
  • parallelrequestget
  • paralellrequestpost
  • paralellrequestdelete
  • parallel_retrieve
  • parallel_list
  • parallellistwithout_pag
  • parallellistone
  • parallel_save
  • parallel_delete
  • paralleldeletemany
  • parallelexecuteaction
  • parallelbulksave
  • parallel_pivot

Owner

  • Name: Murabei Data Science
  • Login: Murabei-OpenSource-Codes
  • Kind: organization
  • Email: contact@murabei.com
  • Location: Brazil

Translating reality to math, a Data Science consulting company

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: Baceti
    given-names: André Andrade
title: "PumpWood Communication"
version: 0.2
date-released: 2021-06-01

GitHub Events

Total
  • Delete event: 6
  • Push event: 24
  • Pull request event: 2
  • Create event: 13
Last Year
  • Delete event: 6
  • Push event: 24
  • Pull request event: 2
  • Create event: 13

Dependencies

requirements.txt pypi
  • SQLAlchemy-Utils ==0.37.8
  • Shapely >=1.7.0
  • geopandas >=0.8.1
  • pandas *
  • requests *
  • simplejson *
src/pumpwood_communication.egg-info/requires.txt pypi
  • SQLAlchemy-Utils ==0.37.8
  • Shapely >=1.7.0
  • geopandas >=0.8.1
  • pandas *
  • simplejson *
setup.py pypi