Metadata-Version: 2.4
Name: saas-core-lib
Version: 0.1.2
Summary: Common core library for all microservices
Author-email: Hasan Bahadır <hasan@hashub.dev>
Project-URL: Homepage, https://github.com/hasanbahadir/saas-core-lib
Project-URL: Bug Reports, https://github.com/hasanbahadir/saas-core-lib/issues
Project-URL: Source, https://github.com/hasanbahadir/saas-core-lib
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Framework :: FastAPI
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi>=0.104.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pydantic-settings>=2.0.0
Requires-Dist: sqlalchemy>=2.0.0
Requires-Dist: alembic>=1.12.0
Requires-Dist: asyncpg>=0.28.0
Requires-Dist: psycopg2-binary>=2.9.0
Requires-Dist: elasticsearch>=8.0.0
Requires-Dist: redis>=4.5.0
Requires-Dist: passlib>=1.7.0
Requires-Dist: bcrypt>=4.0.0
Requires-Dist: python-jose>=3.3.0
Requires-Dist: cryptography>=41.0.0
Requires-Dist: structlog>=23.0.0
Requires-Dist: httpx>=0.25.0
Requires-Dist: python-multipart>=0.0.6
Requires-Dist: email-validator>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: mypy>=1.5.0; extra == "dev"
Requires-Dist: pre-commit>=3.4.0; extra == "dev"
Provides-Extra: unix
Requires-Dist: uvloop>=0.17.0; extra == "unix"
Dynamic: license-file

# SAAS Core Library

Common core library for all microservices in the SAAS platform.

## Features

- **Database Management**: SQLAlchemy 2.0+ async engine with connection pooling
- **Redis Client**: Async Redis client with state and cache databases  
- **Elasticsearch**: Centralized Elasticsearch client management
- **Security**: JWT token management, password hashing, API key handling
- **Logging**: Structured logging with service-specific loggers
- **Response Handling**: Standardized API response formats
- **Configuration**: Environment-based configuration management

## Installation

```bash
pip install saas-core-lib
```

## Usage

### Database

```python
from saas_core_lib import get_db_session, create_tables

# Get database session
async with get_db_session() as session:
    # Your database operations
    pass

# Create all tables
await create_tables()
```

### Redis

```python
from saas_core_lib import get_redis_client

# Get Redis client
redis_client = await get_redis_client()
await redis_client.set("key", "value")
```

### Security

```python
from saas_core_lib import hash_password, verify_password, create_access_token

# Hash password
hashed = hash_password("my_password")

# Verify password
is_valid = verify_password("my_password", hashed)

# Create JWT token
token = create_access_token({"user_id": "123"})
```

### Response Handling

```python
from saas_core_lib import create_success_response, create_error_response, ErrorCode

# Success response
return create_success_response("User created successfully", {"user_id": "123"})

# Error response
return create_error_response("User not found", ErrorCode.NOT_FOUND, 404)
```

### Logging

```python
from saas_core_lib import get_logger, LogLevel, setup_logging

# Setup logging for service
setup_logging("my-service", LogLevel.INFO)

# Get logger
logger = get_logger("my-service")
logger.info("Application started")
```

## Configuration

Set environment variables in `.env` file:

```env
# Database
DATABASE_URL=postgresql+asyncpg://user:pass@localhost/dbname

# Redis  
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=password

# Elasticsearch
ELASTICSEARCH_URL=https://localhost:9200
ELASTICSEARCH_USERNAME=user
ELASTICSEARCH_PASSWORD=pass

# JWT
JWT_SECRET=your-secret-key
JWT_ALGORITHM=HS256
JWT_EXPIRE_DAYS=7
```

## Development

```bash
# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Code formatting
black src/
isort src/

# Type checking
mypy src/
```

## License

MIT License
