Skip to main content

BOSA Core Library

Project description

BOSA Core

BOSA Core is a flexible plugin-based architecture that allows you to build modular and extensible applications. It provides a robust framework for managing plugins, handling dependencies, and injecting services.

Key Features

  • 🔌 Plugin-based Architecture
  • 💉 Dependency Injection
  • 🔄 Service Registry
  • 🛠️ Flexible Plugin Handlers
  • 🌐 HTTP Interface Support
  • 📊 OpenTelemetry Integration
  • 🛡️ Sentry Error Tracking
  • 📜 Logging

Installation

Prerequisites

1. Installation from Pypi

Choose one of the following methods to install the package:

Using pip

pip install bosa-core-binary

Using Poetry

poetry add bosa-core-binary

2. Development Installation (Git)

For development purposes, you can install directly from the Git repository:

poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-core"

Plugin Architecture Overview

Plugin Architecture

How It Works

  1. Plugin Manager: The central piece that orchestrates everything

    • Manages plugin lifecycle
    • Handles service registration
    • Initializes plugins with required dependencies
  2. Service Registry: A container for all services

    • Stores service instances
    • Handles dependency injection
    • Maps service types to their implementations
    • Note: You don't need to create your own Service Registry - it's integrated into the Manager!
  3. Plugin Handler: Interface for providing services to plugins

    • Creates service injections through create_injections
    • Initializes plugin-specific resources
    • Can be extended for different types of plugins (e.g., HTTP handlers)
  4. Plugin: Base class for all plugins

    • Has basic metadata (name, description, version)
    • Receives injected services automatically
    • Can be extended with specific functionality
  5. Open Telemetry: Initializer class to use open telemetry

    • Integrates with OpenTelemetry for tracing and metrics
    • Provides observability for plugins and services
    • Can be configured to export data to various backends (e.g., Jaeger, Prometheus)
  6. Sentry: Initializer class to use sentry

    • Integrates with Sentry for error tracking and performance monitoring
    • Captures exceptions and sends them to Sentry
    • Provides insights into application performance and errors

Authentication

BOSA Core provides a robust, multi-tenancy authentication system, allowing secure client and user management.

  1. Client Management:

    • Clients are created using a Master Key (BOSA_WHITELISTED_KEYS).
    • Each client has a unique API key used for authentication.
    • API Key Format: sk-client-<base64-client-id>.<base64-client-name>.<client-secret>.
    • Clients can manage their users and authentication settings.
  2. User Authentication:

    • Clients create users by providing an identifier.
    • Each user receives a secret, which is displayed only once.
    • Users authenticate using their identifier and secret.
    • User API Key Format: sk-user-<base64-user-id>.<base64-user-identifier>.<user-secret>.
  3. Token-Based Access:

    • Upon authentication, users receive JWT tokens for secure access.
    • Tokens are verified for subsequent requests.
    • Tokens expire after 30 days (default: 43,200 minutes).
    • Tokens can be revoked when necessary.
  4. Third-Party Integrations:

    • Users can create integrations with third-party services.
    • Authentication credentials are securely stored.
    • Each integration can be assigned scoped access.

For detailed implementation, refer to the Authentication README.

Implementation Details

The plugin system works through these key components:

1. Plugin Manager

from fastapi_interface import FastApiHttpInterface

# Create FastAPI handler
fastapi_handler = FastApiHttpInterface()

# Initialize manager with the handler
manager = PluginManager(handlers=[fastapi_handler])
manager.register_plugin(MyPlugin)
  • Initializes the plugin system
  • Manages plugin lifecycle
  • Handles service registration

2. Plugin Handler

from bosa_core.plugin import PluginHandler

class MyHandler(PluginHandler):
    @classmethod
    def create_injections(cls, instance):
        # Tell the manager what services this handler provides
        return {MyService: instance}

    @classmethod
    def initialize_plugin(cls, instance, plugin):
        # Initialize plugin resources
        pass
  • Creates service mappings via create_injections
  • Initializes plugin resources
  • Can be customized for different plugin types

3. Plugin

from bosa_core.plugin import Plugin
from fastapi_interface import FastApiService

class MyPlugin(Plugin):
    # Services will be injected automatically
    fastapi_service: FastApiService

    def __init__(self, name, description, version):
        super().__init__(name, description, version)
  • Base class for all plugins
  • Receives injected services
  • Can be extended with custom functionality

4. Open telemetry external exporter (enable fastapi & langchain instrumentation)

from bosa_core.telemetry import OpenTelemetryConfig, FastAPIConfig, init_telemetry
from fastapi import FastAPI

endpoint = "your-exporter-endpoint"
port = "your-exporter-port"
attributes = {
   "key1":"val1"
}
app = FastAPI()
use_langchain_instrumentation = True
fastapi_config = FastAPIConfig(app=app)
otel_config = OpenTelemetryConfig(endpoint=endpoint, port=port, attributes=attributes, fastapi_config=fastapi_config, use_langchain=use_langchain_instrumentation)
init_telemetry(TelemetryConfig(otel_config=otel_config))

5. Sentry

from bosa_core.telemetry import SentryConfig, init_telemetry

def traces_sampler(sampling_context: dict) -> float:
    """Determine appropriate sampling rate for Sentry transactions.
    Args:
        sampling_context: Context dictionary containing transaction information
    Returns:
        float: Sampling rate between 0 and 1
    """

    ### you can use customization (ex: for certain name sampler will be 0.1) for trace_sampler in this class
    return 1.0


dsn = "your-dsn"
environment = "development/staging/production"
release = "your release tag"
sentry_config = SentryConfig(
        dsn=dsn,
        environment=environment,
        release=release,
        traces_sampler=traces_sampler,
        send_default_pii=True,
    )
init_telemetry(TelemetryConfig(sentry_config=sentry_config))

6. Sentry with Open Telemetry (enable fastapi & langchain instrumentation)

from bosa_core.telemetry import SentryConfig, init_telemetry, FastAPIConfig, OpenTelemetryConfig
from fastapi import FastAPI


def traces_sampler(sampling_context: dict) -> float:
    """Determine appropriate sampling rate for Sentry transactions.
    Args:
        sampling_context: Context dictionary containing transaction information
    Returns:
        float: Sampling rate between 0 and 1
    """

    ### you can use customization (ex: for certain name sampler will be 0.1) for trace_sampler in this class
    return 1.0


dsn = "your-dsn"
environment = "development/staging/production"
release = "your release tag"

attributes = {
   "key1":"val1"
}
app = FastAPI()
use_langchain_instrumentation = True
fastapi_config = FastAPIConfig(app=app)
opentelemetry_init = OpenTelemetryConfig(attributes=attributes, fastapi_config=fastapi_config, use_langchain=use_langchain_instrumentation)

sentry_config = SentryConfig(
        dsn=dsn,
        environment=environment,
        release=release,
        traces_sampler=traces_sampler,
        send_default_pii=True,
        open_telemetry_initiliazer=opentelemetry_init
    )
init_telemetry(sentry_config=sentry_config)

7. Logging Ner API Handler

from bosa_core.logger import init_ner_pii_logging_handler

init_ner_pii_logging_handler(logger_name="logging-name", api_url="https://dev-api-gdplabs-ner-api.obrol.id/anonymize", api_field="text", pii_ner_process_enabled=True)


logger.info("contoh nomor ktp 3525011212941001\ncontoh email john.doe@example.com\ncontoh nomor telepon +628121729819 dan 0812898029384.\ncontoh npwp 01.123.456.7-891.234" ) # if you using gdplabs ner API output will be contoh nomor ktp <ID_KTP_1>\ncontoh email <EMAIL_ADDRESS_1>\ncontoh nomor telepon <PHONE_NUMBER_1> dan <PHONE_NUMBER_2>.\ncontoh npwp <ID_NPWP_1>

[!WARNING] If you are using Logger Ner API handler, the logging process may take some time because it needs to call an API for every log entry synchronously.

8. Logging Regex Handler

from bosa_core.logger import init_regex_pii_logging_handler

init_regex_pii_logging_handler(logger_name="logging-name", pii_regex_process_enabled=True)


logger.info("contoh nomor ktp 3525011212941001\ncontoh email john.doe@example.com\ncontoh nomor telepon +628121729819 dan 0812898029384.\ncontoh npwp 01.123.456.7-891.234" ) # if you using gdplabs ner API output will be contoh nomor ktp <ID_KTP_1>\ncontoh email <EMAIL_ADDRESS_1>\ncontoh nomor telepon <PHONE_NUMBER_1> dan <PHONE_NUMBER_2>.\ncontoh npwp <ID_NPWP_1>

Getting Started

  1. Install dependencies:

    poetry install
    
  2. Create a plugin:

    class MyPlugin(Plugin):
        name = "my-plugin"
        description = "My awesome plugin"
        version = "1.0.0"
    
  3. Register and use:

    # Using FastAPI as an example
    from fastapi import FastAPI
    from fastapi_interface import FastApiHttpInterface
    
    app = FastAPI()
    fastapi_handler = FastApiHttpInterface(app)
    manager = PluginManager(handlers=[fastapi_handler])
    manager.register_plugin(MyPlugin)
    

Development

  • Use Poetry for dependency management
  • Install pre-commit hooks poetry run pre-commit install. This will run checks before each commit.
  • Run ./build.sh to perform all checks:
    • Code formatting and validation (ruff)
    • Documentation style (pydocstyle)
    • Tests (pytest)
    • And more!

References

Product Requirements Documents(PRD):

  • N/A

Architecture Documents:

Design Documents:

Implementation Documents:

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

bosa_core_binary-0.5.5-cp313-cp313-win_amd64.whl (642.1 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.5.5-cp313-cp313-manylinux_2_31_x86_64.whl (955.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_x86_64.whl (759.4 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl (640.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.5.5-cp312-cp312-win_amd64.whl (646.1 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.5.5-cp312-cp312-manylinux_2_31_x86_64.whl (956.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_x86_64.whl (757.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl (639.8 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.5.5-cp311-cp311-win_amd64.whl (646.7 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.5.5-cp311-cp311-manylinux_2_31_x86_64.whl (865.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_x86_64.whl (744.8 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl (624.1 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64macOS 15.0+ ARM64

File details

Details for the file bosa_core_binary-0.5.5-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a34aad02052abf6ede7072036287e9c825a490225fa5c4b0a9b8f3fb0476debf
MD5 63c16870f03e3a7ca96ce4b11c0930d1
BLAKE2b-256 4f456ed6eb7e3635c9a35d7e25a95e47c1d1d84c73a0b7b0ad7f20688735d8ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp313-cp313-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 397ba80b55f45f7139184d7ddb77e3b4e7cfd4c01b5ecaaea4f8958e2d241c92
MD5 c191c3fc4f7dfcb134d7d037ea67f278
BLAKE2b-256 4dd96825e96ac38e7919afbeb17b0f3a5be39dfb9976a6e6dac83044ad3c0705

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 890a5dcc7432de38c18c515ef2938d2c31ba826efee889cdaf118cc2846e1f68
MD5 0049cd3183a62c9c3afe981ab9d73ec0
BLAKE2b-256 fba2c7e0cc73fd893336d670fbfee7f6a2bba89aaa1ef40ba6a89c0eccbbfa9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d7ed959791b7afa06f802eb470be4e9748e23d33217d4690156e272f56e71b73
MD5 4cbe18af26681aeebaccca82f6da785e
BLAKE2b-256 ae39a3d0cd480150309b0b4737ed6becced913689cdbaadde57fa3f5d45b3192

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 34007f7be27147847e98ef53ec68c5ec9fbd1ba572f7b45d07e3464dd159681e
MD5 adceb0c3a65528ce3de7e1b729c3678e
BLAKE2b-256 a1d06882894dd751d971ffc4a6bcf3cc240a465c5f9685c93ca156e6786f36f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 b6afdfa00fa5019bec8aae95393ca1a310a55d46ae894582370c9ce8292c5465
MD5 b8b3e63ad24faa8c5875d91f25193858
BLAKE2b-256 af51dd535482cd700c689270a76eb98ed94b851d69071de642d46fb29dbbd7f5

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 8f2240d6bb860ae5c44f15e8a1a38e7caf39289e7f815b24645b3a9348ee489f
MD5 efab7266b423318a23e8ee8740462aba
BLAKE2b-256 d9e85feb93054c21670696b9c90d69bfc5577e75077ecc16635fc2975d8e73c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 29097e1bb5cd25b0564884fabbc7aaa127a5514815b87df3d0ab3afb0bbc90db
MD5 7fa4fa114bed1687918d1c4e5f3bf62d
BLAKE2b-256 3a541d93f0a9201cb9d5f4fd249aba2a8f3b68c96befa12ba9b9ee7a3f661580

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 78fdfa38016b3db9c32e88f19dcfc768d4285947534cc5622cc3756a8ebca65c
MD5 c53a3290eade103501eba5fae8782889
BLAKE2b-256 16623e987d29a18be5714ca985693616ed1370a3cdf2f2b6f6520787d10ebf13

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 17e8ba1e616f8adf9b9573cf9c83bf17042f4c3cbe5c3de28df8c89a1801ed1b
MD5 92fb296974c24e854bd8f02bd93e1fba
BLAKE2b-256 c52c579bc7c9d314bfd06008ace95c390e7134e6269c2970af5d3a0e04f3453e

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 c3502c2abb72c545a719ddafadf68e469e2c02973a1607dc9a8e656db82f8f77
MD5 1479c0373973220a786622b2a64040a0
BLAKE2b-256 352cbee2548ab72464201ef729a4dafff60d3ebae7566862921f2cf1dfc2345f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 aae22dd1dd31569528a255d38609571c67ca70e73b0ce08c6a939377cf5a3aaf
MD5 dd1a22f684d629ce54cf5edbabae6b7e
BLAKE2b-256 b7dab04906576f5071a6defd1eef189cb29e3a5f24f61041d14a88aad7e3461a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.5-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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