Skip to main content

bisslog-pymongo

It is an extension of the bisslog library to support processes with the pymongo driver library of the mongo db database.

Example usage

import os
from pymongo import MongoClient, DESCENDING
from abc import ABC, abstractmethod
from bisslog import Division, bisslog_db
from bisslog_pymongo import BasicPymongoHelper, bisslog_exc_mapper_pymongo


class MarketingDivision(Division, ABC):

    @abstractmethod
    def find_sales_per_client(self, id_client: int):
        raise NotImplementedError("find_sales_per_client must be implemented")


class MarketingMongoDivision(MarketingDivision, BasicPymongoHelper):

    @bisslog_exc_mapper_pymongo
    def find_sales_per_client(self, id_client: int):
        res = self.get_collection("sales").find({"id_client": id_client}).sort(
            {'created_at': DESCENDING})
        return self.stringify_list_identifier(res)


marketing_div = MarketingMongoDivision(MongoClient(os.environ["ATLAS_URI"]),
                                       database_name="marketing")

bisslog_db.register_adapters(marketing=marketing_div)

Components

PymongoHelper

It is just a class that receives the client and has some methods to facilitate the creation of pymongo adapters. the creation of pymongo adapters

bisslog_exception_handler_pymongo

Decorator to map PyMongo exceptions to their corresponding Bisslog exceptions.

Excepción de PyMongo Excepción de Bisslog
DuplicateKeyError IntegrityErrorExtException
BSONError InvalidDataExtException
CollectionInvalid ProgrammingErrorExtException
ConfigurationError ConfigurationExtException
NetworkTimeout TimeoutExtException
WriteError IntegrityErrorExtException
ConnectionFailure ConnectionExtException
OperationFailure OperationalErrorExtException
PyMongoError ExternalInteractionError

BasicPymongoHelper

BasicPymongoHelper is a helper class for interacting with MongoDB databases using PyMongo.
It provides convenient methods for performing CRUD operations while maintaining traceability through TransactionTraceable.

Initialization

BasicPymongoHelper(mongo_client: MongoClient, database_name: str = None)

Initializes the helper with a MongoClient instance.

If database_name is not provided, it uses the default database.

Methods

  • get_collection
get_collection(collection_name: str, database_name: str = None) -> Collection

Returns the collection object from the specified database.

If database_name is not provided, it defaults to the instance's database.

  • insert_one
insert_one(collection: str, obj: object = None, *, save_id: bool = False, **kwargs) -> str

Inserts a document into the specified collection.

If save_id is False, it removes the _id field before insertion.

Returns the inserted document's ID as a string.

  • find_one
find_one(collection: str, query: dict, selection: dict) -> dict

Retrieves a single document from the specified collection based on query and selection.

Converts the document’s _id to a string before returning.

  • stringify_identifier
@classmethod
stringify_identifier(cls, obj: dict) -> dict

Converts an ObjectId _id field to a string in a single document.

  • stringify_list_identifier
@classmethod
stringify_list_identifier(cls, list_obj: Iterator) -> list

Converts the _id field to a string in a list of documents.

  • verify_query
@staticmethod
verify_query(query: dict) -> dict

Validates and processes a query:

Converts _id field to ObjectId if necessary.

Ensures the query is a dictionary.

Returns None if validation fails.

  • get_length
get_length(collection: str, query: dict) -> int

Returns the number of documents matching the given query in a collection.

Metadata

Release files for bisslog-pymongo 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bisslog-pymongo 0.0.1
File Size Uploaded Provenance
bisslog_pymongo-0.0.1.tar.gz 15.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bisslog-pymongo 0.0.1
File Interpreter ABI Platform
bisslog_pymongo-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / bisslog_pymongo-0.0.1.tar.gz

Download URL bisslog_pymongo-0.0.1.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5a547d85b74823a6ac8473489c945e68cfa611b2873a605455f3ad69240b39d7
BLAKE2b-256 checksum
How to use checksums
9adfa4da39e638c573de457d55339ccff80c618124c13a5f3f3a4f064b374485
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / bisslog_pymongo-0.0.1-py3-none-any.whl

Download URL bisslog_pymongo-0.0.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb2c75440cf41d8c332f350499abaf22f82bff27570496e416f04412405756f4
BLAKE2b-256 checksum
How to use checksums
1afb794bd55e95172b6416c0641f00cc84e7dd2adba06416167b85ff60fc0e2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for bisslog-pymongo 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page