A central repository for shared logic and utilities across microservices.
Project description
common_library
common_library is a centralised repository for shared logic and utilities across microservices. It consolidates core functionalities—such as unique ID generation, constructing nodes/diagrams/relationships, and managing Neo4j connections—into one versioned package. This approach enables each microservice to explicitly declare and manage its dependencies while ensuring consistency, reducing redundancy, and allowing controlled updates.
Overview
The common_library provides the following components:
-
Factories:
- DiagramFactory: Creates standardised diagram payloads. It supports an optional builder callback (or registration) so that consuming microservices can convert these payloads into their own domain-specific model instances (e.g. IDEF0 diagrams).
- NodeFactory: Generates node payloads for various node types (such as "function" or "element") with customisable builders.
- RelationshipFactory: Constructs relationship (edge) payloads to standardise the formation of graph database queries.
-
BaseRepository:
An abstract repository that encapsulates common operations for interacting with a Neo4j database. It handles driver initialisation, session management, logging, error handling, and query execution. Microservices can inherit from this class to implement domain-specific data access methods while reusing core functionality.
Architecture & Workflow
Below are Mermaid diagrams illustrating how the library interacts with microservices.
1. Package Publishing & Consumption
flowchart TD
A[common_library Repository] -->|Build & Publish Package| B[GitHub Packages Registry]
B -->|Import Package| C[Microservice A]
B -->|Import Package| D[Microservice B]
C -->|Uses shared code| E[Domain-Specific Logic]
D -->|Uses shared code| E
2. Diagram Creation Workflow
flowchart LR
A[Diagram Microservice] --> B[Import DiagramFactory]
B --> C[Call DiagramFactory.create_diagram("IDEF0", ...)]
C --> D[Generic Diagram Payload is Generated]
D --> E{Is a builder supplied?}
E -- Yes --> F[Convert payload into a domain-specific IDEF0Diagram model]
E -- No --> G[Return generic dictionary payload]
3. Node and Relationship Generation
flowchart TD
A[Node Microservice] --> B[Import NodeFactory & RelationshipFactory]
B --> C[Create a "function" node using NodeFactory.create_node("function", ...)]
B --> D[Create an "element" node using NodeFactory.create_node("element", ...)]
B --> E[Generate a relationship using RelationshipFactory.create_relationship(...)]
4. BaseRepository Integration
flowchart LR
A[Microservice Repository Layer] --> B[Import BaseRepository]
B --> C[Subclass BaseRepository in a CustomRepo]
C --> D[CustomRepo Executes Domain-Specific Queries]
D --> E[Interacts with Neo4j via GraphDatabase.driver]
Installation & Setup
Install the package (once available) via:
pip install common_library==<version>
Alternatively, configure the internal package manager (e.g. GitHub Packages) in a microservice’s dependency file (such as pyproject.toml):
[project]
dependencies = [
"common_library==<version>"
]
[tool.uv.sources]
common_library = { index = "your-internal-pypi" }
Usage Examples
Importing the Library in a Microservice
# Import factories and the base repository
from common_library.factories.diagram_factory import DiagramFactory
from common_library.factories.node_factory import NodeFactory
from common_library.factories.relationship_factory import RelationshipFactory
from common_library.repositories.base_repository import BaseRepository
# Example: Create a diagram with an inline builder (if needed)
def idef0_builder(**payload):
# Convert payload into a service-specific IDEF0Diagram instance
from my_diagram_service.models.idef0_diagram import IDEF0Diagram
return IDEF0Diagram(**payload)
diagram = DiagramFactory.create_diagram(
diagram_type="IDEF0",
name="Operational Diagram",
project_id="Proj-123",
builder=idef0_builder # Omit if a plain payload is preferred
)
print("Diagram:", diagram)
# Example: Create a function node
node = NodeFactory.create_node("function", name="Data Processor")
print("Node:", node)
# Example: Create a relationship between nodes
relationship = RelationshipFactory.create_relationship(
rel_type="CONNECTS", source_id="N-abc", target_id="N-def"
)
print("Relationship:", relationship)
# Example: Using BaseRepository to interact with Neo4j
class MyNeo4jRepository(BaseRepository):
def create_node_in_db(self, node_payload):
query = "CREATE (n $props) RETURN n"
return self.execute_query(query, {"props": node_payload})
# Initialise repository with connection details
repo = MyNeo4jRepository(uri="bolt://neo4j:7687", user="neo4j", password="secret")
result = repo.create_node_in_db(node)
print("Query result:", result)
repo.close()
Explaining the Flow
-
Diagram Service:
- Imports
DiagramFactoryand registers (or supplies inline) a builder function. - Calls
create_diagramto obtain either a generic payload or a fully instantiated domain model.
- Imports
-
Node Service:
- Uses
NodeFactoryto create nodes andRelationshipFactoryto establish relationships.
- Uses
-
Repository Layer:
- Inherits from
BaseRepositoryto manage Neo4j connectivity, execute queries, and log errors robustly.
- Inherits from
Additional Mermaid Diagrams
Overall Interaction Diagram
flowchart TD
A[Microservice Script] -->|Imports| B[common_library Components]
B --> C[Generate Payloads for Diagrams, Nodes, Relationships]
C --> D[Optional: Convert Payloads via Builder Functions]
D --> E[Domain-Specific Models]
B --> F[BaseRepository Operations]
F --> G[Execute Cypher Queries on Neo4j]
Microservice Import & Usage Example
sequenceDiagram
participant M as Microservice
participant CL as common_library
participant DB as Neo4j
M->>CL: import factories & BaseRepository
M->>CL: create node/diagram via factories
M->>CL: optionally register builder functions
M->>DB: execute queries via custom repository subclassing BaseRepository
Future Enhancements
-
Extensibility:
New builder functions can be registered to support additional diagram or node types without modifying the core library. -
Enhanced Documentation:
Future releases may include auto-generated documentation from docstrings (e.g. via Sphinx) with more detailed examples. -
Robust Testing:
The library is thoroughly tested usingpytest, ensuring reliability as features and integrations evolve.
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 std_methods-0.1.0.tar.gz.
File metadata
- Download URL: std_methods-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ae54b2f75fa697d1c707e45309e710b08ba000b288271d2d75f6fc2723e440
|
|
| MD5 |
48ce85941c1f77466e5445b2dd4bf214
|
|
| BLAKE2b-256 |
a6a141313f01f63ca652ec1868c041087c3d1c6b369fc36d718fe341b94a8c4d
|
Provenance
The following attestation bundles were made for std_methods-0.1.0.tar.gz:
Publisher:
publish.yml on OpenForte/common_library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
std_methods-0.1.0.tar.gz -
Subject digest:
78ae54b2f75fa697d1c707e45309e710b08ba000b288271d2d75f6fc2723e440 - Sigstore transparency entry: 179629127
- Sigstore integration time:
-
Permalink:
OpenForte/common_library@7cb5be6b6f727074aea5275aaf59e0f9621df136 -
Branch / Tag:
refs/tags/v00.1.0 - Owner: https://github.com/OpenForte
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7cb5be6b6f727074aea5275aaf59e0f9621df136 -
Trigger Event:
push
-
Statement type:
File details
Details for the file std_methods-0.1.0-py3-none-any.whl.
File metadata
- Download URL: std_methods-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cce45e15b2583823661a31a32251a7a5d266e1e3400556d1542486f8fc6ee03
|
|
| MD5 |
1ecf5496ad864f9051a40f1820b52edd
|
|
| BLAKE2b-256 |
8105dc263922f1cfb8badbd6b6352cf0b9d90d27e21a19ddf6a20e7aca65daaf
|
Provenance
The following attestation bundles were made for std_methods-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on OpenForte/common_library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
std_methods-0.1.0-py3-none-any.whl -
Subject digest:
2cce45e15b2583823661a31a32251a7a5d266e1e3400556d1542486f8fc6ee03 - Sigstore transparency entry: 179629132
- Sigstore integration time:
-
Permalink:
OpenForte/common_library@7cb5be6b6f727074aea5275aaf59e0f9621df136 -
Branch / Tag:
refs/tags/v00.1.0 - Owner: https://github.com/OpenForte
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7cb5be6b6f727074aea5275aaf59e0f9621df136 -
Trigger Event:
push
-
Statement type: