Skip to content

pyconvexity

Python library for energy system modeling and optimization with PyPSA.

Overview

pyconvexity is the Python library that powers Convexity, providing programmatic access to energy system modeling and optimization. It stores models in SQLite databases and integrates with PyPSA for solving.

What is pyconvexity?

pyconvexity is designed for users who want to:

  • Automate model creation and analysis workflows
  • Integrate Convexity models into larger data pipelines
  • Batch process parametric studies and sensitivity analyses
  • Access and manipulate model data programmatically
  • Build custom analysis tools on top of Convexity models

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']}")

Working with Database Files

Convexity stores all model data in SQLite database files (.db files). These files contain:

  • Network topology - buses, generators, lines, etc.
  • Component parameters - capacities, costs, efficiencies
  • Time series data - load profiles, renewable generation
  • Scenario definitions - alternative parameter sets
  • Optimization results - dispatch, prices, flows

pyconvexity provides a complete API for reading, writing, and manipulating these database files.

Key Capabilities

Data Management

  • Ultra-fast time series handling with binary serialization
  • Efficient database operations for large-scale models
  • Attribute validation and type safety

PyPSA Integration

  • Seamless conversion between Convexity and PyPSA formats
  • Full PyPSA component support
  • Batch data loading for performance

Optimization

  • Multiple solver support (HiGHS, Gurobi, CPLEX, etc.)
  • Custom constraint integration
  • Result analysis and post-processing

When to Use pyconvexity

Use the Convexity AppUse pyconvexity
Visual, interactive interfaceAutomate repetitive tasks
Building models from scratchIntegrate with Python workflows
No-code preferredBatch simulations
Collaboration with non-programmersCustom data processing

Next Steps

Need Help?

pyconvexity is an advanced tool that requires Python programming knowledge. If you need assistance, please contact us.

© Copyright 2025 Bayesian Energy