OpenBioCure_CoreLib on PyPI
OpenBioCure_CoreLib

OpenBioCure_CoreLib is the foundational core library for the HerpAI platform. It provides shared infrastructure components, configuration management, logging utilities, database session handling, and the repository pattern used across HerpAI agents and services.
๐ Documentation
- See the changelog at the bottom of this file for recent updates.
Come chat with us on Discord: HerpAI Discord Server
๐ฆ Features
- ๐ง Dependency Injection - Service registration and resolution
- ๐ Repository Pattern - Type-safe entity operations
- ๐ Specification Pattern - Fluent query filtering
- ๐งต Async Support - Full async/await patterns
- ๐ Type Safety - Generic interfaces with Python typing
- โ๏ธ Configuration Management - YAML with dataclass validation and OOP interface
- ๐ Auto-discovery Startup System - Ordered initialization with configuration
- ๐ชต Structured Logging - Consistent format across components
๐ What's New in 3.1.0
- Core symbols like
IRepository
, Repository
, BaseEntity
, Specification
, YamlConfig
, Environment
, StartupTask
, and AppConfig
are now exposed directly from the root package.
- This simplifies imports. For example:
from openbiocure_corelib import IRepository, Repository, BaseEntity, Specification, YamlConfig, Environment, StartupTask, AppConfig
- Created a dedicated release branch
release-3.1.0
containing these changes.
- See the Changelog for full details.
๐ ๏ธ Installation
pip install openbiocure-corelib
Or install from GitHub:
pip install git+https://github.com/openbiocure/HerpAI-Lib.git
For development:
git clone https://github.com/openbiocure/HerpAI-Lib.git
cd HerpAI-Lib
pip install -e .
โก Quick Examples
Basic Todo Repository
import asyncio
from openbiocure_corelib import engine
from examples.domain.todo_entity import Todo
from examples.repository.todo_repository import ITodoRepository, CompletedTodoSpecification
async def main():
engine.initialize()
await engine.start()
todo_repo = engine.resolve(ITodoRepository)
todo = Todo(title="Learn OpenBioCure_CoreLib", description="Use DI and repository", completed=False)
created = await todo_repo.create(todo)
created.completed = True
await todo_repo.update(created)
completed_todos = await todo_repo.find(CompletedTodoSpecification())
print(f"Completed todos: {len(completed_todos)}")
asyncio.run(main())
Accessing YAML Configuration
from openbiocure_corelib import engine, YamlConfig
engine.initialize()
config = engine.resolve(YamlConfig)
print(config.get('database.host'))
print(config.get('app.default_model_provider'))
Custom Startup Task
from openbiocure_corelib import StartupTask
class MyStartupTask(StartupTask):
order = 50
async def execute(self):
print("Running my startup task!")
Advanced Database Queries with Specifications
from openbiocure_corelib import Specification
class UserByUsernameSpec(Specification):
def __init__(self, username):
self.username = username
def to_expression(self):
from myapp.models import User
return User.username == self.username
user_repo = engine.resolve(IUserRepository)
user = await user_repo.find_one(UserByUsernameSpec("johndoe"))
๐ Examples
๐ Library Structure
openbiocure_corelib/
โโโ config/
โ โโโ app_config.py
โ โโโ dataclass_config.py
โ โโโ environment.py
โ โโโ settings.py
โ โโโ yaml_config.py
โโโ core/
โ โโโ configuration_startup_task.py
โ โโโ engine.py
โ โโโ interfaces.py
โ โโโ service_collection.py
โ โโโ service_scope.py
โ โโโ singleton.py
โ โโโ startup_task_executor.py
โ โโโ startup_task.py
โ โโโ type_finder.py
โโโ data/
โ โโโ db_context_startup_task.py
โ โโโ db_context.py
โ โโโ entity.py
โ โโโ repository.py
โ โโโ specification.py
โโโ domain/
โโโ infrastructure/
โ โโโ caching/
โ โโโ events/
โ โโโ logging/
โโโ utils/
๐งช Requirements
- Python 3.9+
- SQLAlchemy
- PyYAML
- aiosqlite
- dataclasses (built-in for Python 3.9+)
๐ License
This library is released under the MIT License as part of the OpenBioCure initiative.
Changelog
All notable changes to this project will be documented here.
The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.
[0.2.1] - 2025-04-05
Changed
- Renamed the library to
openbiocure_corelib
- Updated project metadata and package name accordingly
- Bumped version to 0.2.1
[Unreleased]
Added
- Test database directory fixture (
test_db_dir
) to create temporary directory for test database files
- Support for direct database connection string configuration
- Proper cleanup in
initialized_engine
fixture
- Comprehensive test cases for error handling and edge cases in Repository
- CI environment detection to use in-memory databases in CI
Changed
- Updated test configuration to use temporary database path
- Improved database context startup task to handle both connection string and individual parameters
- Modified
Engine.current()
test to properly await engine start
- Updated
Repository.update
method to handle both string IDs and entity objects
- Enhanced validation in TestEntity to properly raise SQLAlchemyError for null name
- Updated Engine.stop() method to properly clear ServiceCollection without using non-existent clear() method
- Modified test configuration to use in-memory databases in CI environments
Fixed
- Database path issues in CI environment
- SQLite database file access in tests
- Immutable fields handling in Repository updates
- Test startup tasks to utilize async execute methods
- RuntimeError: 'Engine not started' by ensuring proper engine initialization
- AttributeError in Engine.stop() method when clearing ServiceCollection
- SQLite database access errors in CI by using in-memory databases
Improved
- Test coverage for repository operations
- Error handling in CRUD operations
- Edge case handling in find operations
- Documentation about the async startup process