semvec/pypi-packages huggingface dataset:
investify-utils 2.0.0a13
Shared utilities for Investify services
License: MIT
Requires Python: >=3.12

# investify-utils

Shared utilities for Investify services.

## Installation

```bash
# Sync PostgreSQL client (psycopg3 + SQLAlchemy + pangres)
pip install investify-utils[postgres]

# Async PostgreSQL client (asyncpg + SQLAlchemy)
pip install investify-utils[postgres-async]
```

## PostgreSQL Clients

### Sync Client (PostgresClient)

Uses psycopg3 + SQLAlchemy for connection pooling, pangres for upsert.

```python
from investify_utils.postgres import PostgresClient

client = PostgresClient(
    host="localhost",
    port=5432,
    username="user",
    password="pass",
    database="db",
    # SQLAlchemy pool options
    pool_size=5,
    pool_recycle=3600,
)

# Read
df = client.read("SELECT * FROM table")

# Insert (uses COPY protocol)
client.insert(df, table="my_table", schema="public")

# Upsert (DataFrame index = primary keys)
df = df.set_index(["id"])
client.upsert(df, table="my_table", schema="public")

# Execute DDL/DML
client.execute("DELETE FROM table WHERE id = 1")

# Close (important for Celery workers)
client.close()
```

### Async Client (AsyncPostgresClient)

Uses asyncpg + SQLAlchemy async engine. Read-only.

```python
from investify_utils.postgres import AsyncPostgresClient

client = AsyncPostgresClient(
    host="localhost",
    port=5432,
    username="user",
    password="pass",
    database="db",
    # SQLAlchemy pool options
    pool_size=5,
    pool_recycle=3600,
)

# In async context
df = await client.read("SELECT * FROM table")
await client.close()

# Or as context manager
async with AsyncPostgresClient(...) as client:
    df = await client.read("SELECT * FROM table")
```

## Celery Integration

Both clients use lazy initialization, safe for Celery prefork workers.

```python
# instances/postgres_core.py
from investify_utils.postgres import PostgresClient
from config import settings

postgres_core = PostgresClient(**settings.postgres.model_dump())
```

```python
# celery_app.py
from celery.signals import worker_process_init

@worker_process_init.connect
def init_worker(**_kwargs):
    # Reset engine for each worker (optional with lazy init)
    from instances.postgres_core import postgres_core
    postgres_core.close()
```

## Development

```bash
uv sync
uv run ruff check investify_utils/
```
pyconvexity 0.5.1.post3
Python library for energy system modeling and optimization with PyPSA
License: MIT
Requires Python: >=3.9

# pyconvexity

Python library for energy system modeling and optimization with PyPSA.

[![PyPI version](https://badge.fury.io/py/pyconvexity.svg)](https://badge.fury.io/py/pyconvexity)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Overview

pyconvexity is the Python library that powers [Convexity](https://bayesian.energy/convexity), providing programmatic access to energy system modeling and optimization. It stores models in SQLite databases and integrates with PyPSA for solving.

## Installation

```bash
pip install pyconvexity
```

With optional dependencies:

```bash
pip install pyconvexity[pypsa]     # PyPSA solver integration
pip install pyconvexity[excel]     # Excel import/export
pip install pyconvexity[all]       # All optional dependencies
```

## Quick Start

```python
import pyconvexity as px

# Create a new model database
px.create_database_with_schema("my_model.db")

# Create a network
with px.database_context("my_model.db") as conn:
    network_req = px.CreateNetworkRequest(
        name="My Network",
        start_time="2024-01-01 00:00:00",
        end_time="2024-01-01 23:00:00",
        time_resolution="PT1H",
    )
    px.create_network(conn, network_req)
    
    # Create components
    carrier_id = px.create_carrier(conn, name="AC")
    bus_id = px.create_component(conn, "BUS", "Main Bus", carrier_id=carrier_id)
    
    conn.commit()

# Solve the network
result = px.solve_network("my_model.db", solver_name="highs")
print(f"Success: {result['success']}, Objective: {result['objective_value']}")
```

## Documentation

Full documentation is available at: **[docs.bayesian.energy](https://docs.bayesian.energy/convexity/user-guide/advanced-features/pyconvexity/)**

- [API Reference](https://docs.bayesian.energy/convexity/user-guide/advanced-features/pyconvexity/api/api-reference)
- [Examples & Tutorials](https://docs.bayesian.energy/convexity/user-guide/advanced-features/pyconvexity/examples/example-1/)

## Development

### Setup

```bash
git clone https://github.com/bayesian-energy/pyconvexity.git
cd pyconvexity
pip install -e ".[dev,all]"
```

### Running Tests

```bash
pytest
```

### Documentation Deployment

API documentation is auto-generated and synced to [bayesian-docs](https://github.com/bayesian-energy/bayesian-docs).

**Generate API docs locally:**

```bash
python scripts/generate_api_docs.py --output-dir api-docs
```

**How it works:**
1. On push to `main` or release, the `sync-docs.yml` workflow runs
2. It generates API markdown from Python docstrings
3. Commits the generated docs to the `bayesian-docs` repository

**Setup for maintainers:**
- Add `DOCS_DEPLOY_TOKEN` secret to the repo (personal access token with `repo` scope for bayesian-docs)

## License

MIT License - see [LICENSE](LICENSE) for details.