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.9.2-cp313-cp313-win_amd64.whl (734.5 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.9.2-cp313-cp313-manylinux_2_31_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.9.2-cp313-cp313-macosx_13_0_x86_64.whl (907.4 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

bosa_core_binary-0.9.2-cp312-cp312-win_amd64.whl (739.7 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.9.2-cp312-cp312-manylinux_2_31_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.9.2-cp312-cp312-macosx_13_0_x86_64.whl (905.6 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

bosa_core_binary-0.9.2-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl (754.0 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.9.2-cp311-cp311-win_amd64.whl (746.2 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.9.2-cp311-cp311-manylinux_2_31_x86_64.whl (991.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.9.2-cp311-cp311-macosx_13_0_x86_64.whl (882.4 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

bosa_core_binary-0.9.2-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl (737.6 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64macOS 15.0+ ARM64

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f43c79b2e133e0d00cd4088d33e9033c91631b200e9ee50ca9de966beb028c95
MD5 007af7bfd2b4fef548089814cd25668d
BLAKE2b-256 cb1841ca6fc3faa1b59f28eb06b9cca43eb10ec0fff6949596512061588e5ebc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 e16faa6363eea96003f171f531e095a58c41077eff954fb2ec700c1ebbb495f8
MD5 1299d80af6c60e546d6c9b023e191d2a
BLAKE2b-256 49ddb45d634a1ff20f3958a935d9baa6089e6856e4412b0e7aaa331c250af35c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b13d0f39142a3a6a4f428ac14cc6c1c0dc3dd4d5ae64c0e770d29a18c856df4a
MD5 ebc7b87ac82fc59272ca7f60eef4843f
BLAKE2b-256 cdce82910e42027f2f4cc5033e5cb3996bb4314e12f1af51e421833a535e3bb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6051d7d523fc314ebfa1efc0a8ec0d9f699f4346496c19ee1602787f0dc389d3
MD5 fa20d02279e228f5283872760900800a
BLAKE2b-256 4a3e105b8e9ed4c4bfba66edb5a3486acfb3f5b03cb502e69563114d240cddb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 1bdd186fe46a34d7437cc83e664c045e7fa54cd9b5ab0cc144351cbde6cc02fe
MD5 379374ee50fe37521a180caf55b39807
BLAKE2b-256 63568b6f6e935240b7e03b34def06a79777f690bc87e9ca6799eda7b11002291

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b4b31f3b5990418f79240764c97fef415c305f4f110f5a77c139ed7054724838
MD5 63c6ee4e164ab3f36a778d0cb6f2a980
BLAKE2b-256 15f07aafcb66b9ecc02e7a0b234802d3c017a6c74d05e5c94633eef06871d887

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 381def138ed6feb9be953df990679c0e19cdb30f6fb8dc99dec0a1e1c8a5df5b
MD5 a523241004753b3e729e934e21e2f27f
BLAKE2b-256 7736e9f76ea11f88de34311a254245e86d2bf40fc105578ec765a26e353a238b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 aa00c26fa374ea56bcf134a5a7661a13ff58d7d6f9810afbb4f14d55e072ab03
MD5 2d7e0d3d53bfeb5899cc7be5bb13ec18
BLAKE2b-256 6a469a25280f29b9d5fbac97c268bb3c612646ef0626f2155c4e3d492bfa3905

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 cae3a39a452dd0a2c35aedf6a8366e1ca91a50cc10ab8ca10562f2b3a921f6d5
MD5 a3a5d9ea4fb6768988ddaff280d11bfd
BLAKE2b-256 c6756eaea4d3702b2996b9de42215c9df6e584dd17f040910102769fbd4b75e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 4702a6e8b7365637d0ce0cb667d5dd45c876bd206bbfc2cbd488c74b364f2a50
MD5 3e2a2ed7a85cb21cfcf7c501275653dd
BLAKE2b-256 c6c0e56cca25528b74a808eaa59ead4140d0c94587df6fe76a9a3eb8e9634116

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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.9.2-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.2-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 dcec8dbc64763fb076986dc30b418caa0ad1e921f50e7e9788b2302965ffa3d1
MD5 874db0290151de9572442e5d8cc6c64b
BLAKE2b-256 42dc6e9720206c6162c43eceaf4f1c5bde1c5689759d5b0a7fdec3efd8f4904e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.2-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