Miscellaneous class and funcitions used in Pumpwood
Project description
Pumpwood Miscellaneous
Pumpwood miscellaneous functions and classes.
pumpwood-miscellaneous .
Pumpwood is a native brasilian tree
which has a symbiotic relation with ants (Murabei)
Description
This is a module with miscellaneous functions and classes used in Pumpwood System. These helps from adjusting static file provider (AWS S3, Google Bucket, Azure blob), connect, read and publish messages in RabbitMQ, and other functionalities.
pumpwood_miscellaneous.database
Functions to help connect and build SQLAlchemy query strings.
SQLAlchemyPostGres
Class to substitute SQLAlchemy/Flask database, it integrates with Pumpwood Communication pumpJsonDump that serilize complex objects like shapely BaseGeometry, pandas dataframes and Numpy arrays. It also requery a pre_ping request for each query, invalidating not functional connections.
from flask import Flask, jsonify
from pumpwood_miscellaneous.models import FlaskPumpWoodBaseModel
from pumpwood_communication.serializers import PumpWoodJSONEncoder
db = SQLAlchemyPostGres(model_class=FlaskPumpWoodBaseModel)
def create_app(config_dict, test=False):
"""Create and return app."""
app = Flask(__name__)
app.json_encoder = PumpWoodJSONEncoder
db.app = app
db.init_app(app)
pumpwood_miscellaneous.models
Class and function to help definition of flask models.
FlaskPumpWoodBaseModel
Add a default a BigInteger field id for all models.
pumpwood_miscellaneous.query
Convert dictionary payload to a SQLAlchemy query. Make similar query to Django filter, exclude and order_by ORM API.
from models import User
from pumpwood_miscellaneous.query import SqlalchemyQueryMisc
query_result = SqlalchemyQueryMisc.sqlalchemy_kward_query(
object_model=User,
filter_dict={
"name__icontains": "Jonh",
"age__gte": 30
},
exclude_dict={
"company__in": ["Murabei", "Data Random Corp"]
},
order_by=["name", "-age"]
).limit(50).all()
pumpwood_miscellaneous.rabbitmq
Manage connections with rabbitmq.
PumpWoodRabbitMQ
Help sending msg to RabbitMQ queues, it is possible to "lazy" set constructor variables using init function. Send function uses PumpWoodJSONEncoder, making it possible to send complex objects as msg payload.
from pumpwood_miscellaneous.rabbitmq import PumpWoodRabbitMQ
not_lazy_worker = PumpWoodRabbitMQ(
queue="some-queue",
username="some-user",
password="with-a-strong-pass"
host="1.2.3.4"
port=5672)
not_lazy_worker.send({
"pandas": pd.DataFrame({
"process_data": [1, 2, 3, 4],
"time": pd.to_datatime([
"2021-01-01", "2021-02-01", "2021-03-01", "2021-04-01"])
}),
"ok": "so-ok"})
lazy_worker = PumpWoodRabbitMQ()
lazy_worker.init(
queue="some-queue",
username="some-user",
password="with-a-strong-pass"
host="1.2.3.4"
port=5672
)
pumpwood_miscellaneous.storage
Make the interaction with different storage backends using the same API. So far Google bucket and AWS S3 were implemented.
PumpWoodStorage
from pumpwood_miscellaneous.storage import PumpWoodStorage
storage_google = PumpWoodStorage(
storage_type="google_bucket",
base_path="base_path/for/files/"
bucket_name="some_bucket")
file_data = storage_google.read_file("file_path/file.joblib")
self.storage_google.delete_file("file_path/file.joblib")
storage_google = PumpWoodStorage(
storage_type="aws_s3",
base_path="base_path/for/files/"
bucket_name="some_s3")
file_data = storage_google.read_file("file_path/file_2.joblib")
self.storage_google.delete_file("file_path/file_2.joblib")
allowed_extension
Check if file extension is in a list.
allowed_extension(
filename="file.xlsx", allowed_extensions=["xls", "xlsx", "parquet"],
exception=Exception)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pumpwood_miscellaneous-1.1.7.tar.gz.
File metadata
- Download URL: pumpwood_miscellaneous-1.1.7.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0aa8cbd6d0277955ce45b71f1fc13d528bb07ab0d2120cc6015151bc2a0ce7fd
|
|
| MD5 |
584facee0c13797d4dc7e413e25c1d0b
|
|
| BLAKE2b-256 |
022e1ce8778f86f22b557e10b6f972d5018759eaec9104d22257ade28ca244f9
|
File details
Details for the file pumpwood_miscellaneous-1.1.7-py3-none-any.whl.
File metadata
- Download URL: pumpwood_miscellaneous-1.1.7-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72ac207c6a10fba470852310f0a10a5f680d7f0deaf32b4b0465be723490479f
|
|
| MD5 |
466c2be95826b580da94dcfd6b407f08
|
|
| BLAKE2b-256 |
c545d125a164497668482cc276ac8d1056b6429f1415f539267583637510e700
|