Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pumpwood_miscellaneous-1.1.5.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pumpwood_miscellaneous-1.1.5-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file pumpwood_miscellaneous-1.1.5.tar.gz.

File metadata

  • Download URL: pumpwood_miscellaneous-1.1.5.tar.gz
  • Upload date:
  • Size: 19.1 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

Hashes for pumpwood_miscellaneous-1.1.5.tar.gz
Algorithm Hash digest
SHA256 30585bed8de259f61535aa92ddb6e2adc8d908c58f68ad5c0e2401303d6d182b
MD5 2c13bd6a96c427d40c35cd4525f906b2
BLAKE2b-256 13bac82d8150740febaee4007fd06865af6d50ff24589664f38834b247eb1084

See more details on using hashes here.

File details

Details for the file pumpwood_miscellaneous-1.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for pumpwood_miscellaneous-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d7c394db3788f1eefd55b2c136b0c8dc9389d587a4aac718b10f36a5611ed46e
MD5 e5eab74aaf112fff864b9678ff7454bc
BLAKE2b-256 734b0f5835d527a0a0bbedb5e33a5b57d93cb51308906d07b55a3f2cdffca038

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page