AClimate V3 ORM is an Object-Relational Mapping package designed for the AClimate platform. It facilitates interaction with relational databases for climate data models, forecast systems, agricultural zones, and administrative boundaries. The package provides a structured interface for accessing and manipulating climate historical data at different temporal resolutions.
This is an ORM (Object-Relational Mapping) built with the SQLAlchemy library for interfacing with relational databases.
For complete documentation, visit the
- Modular structure organized by domain (climate, forecast, catalog, administrative, etc.)
- Built using SQLAlchemy for efficient relational mapping
- Compatible with Python > 3.10
- Designed for integration into larger AClimate infrastructure
- Python > 3.10
- Relational database (PostgreSQL recommended, also compatible with MySQL and SQLite)
- Dependencies: SQLAlchemy, psycopg2, python-dotenv, typing_extensions, pydantic
Install directly from GitHub:
pip install git+https://github.com/CIAT-DAPA/aclimate_v3_orm
To install a specific version:
pip install git+https://github.com/CIAT-DAPA/aclimate_v3_orm@v0.0.9
You can configure the database connection either by:
- Creating a
.env
file in your project root, OR - Setting environment variables directly in your system
Create a file named .env
with these configurations:
DATABASE_URL=postgresql://username:password@localhost:5432/database
- Windows (CMD/PowerShell)
set DATABASE_URL=postgresql://username:password@localhost:5432/database
- Linux/Ubuntu (Terminal)
export DATABASE_URL="postgresql://username:password@localhost:5432/database"
Note
Replace username, password and localhost with your actual credentials
Examples
# Models
from aclimate_v3_orm.models import (
ClimateHistoricalMonthly,
MngCountry,
MngLocation
)
#Services
from aclimate_v3_orm.services import (
ClimateHistoricalMonthlyService,
MngCountryService,
MngLocationService
)
#Schemas
from aclimate_v3_orm.schemas import (
LocationCreate, LocationRead, LocationUpdate,
CountryCreate, CountryRead, CountryUpdate,
ClimateHistoricalClimatologyCreate, ClimateHistoricalClimatologyRead, ClimateHistoricalClimatologyUpdate
)
#Init service
country_service = MngCountryService()
#Create new register
new_country = CountryCreate(
name= "Colombia",
iso2= "CL",
enable= True
)
country = country_service.create(obj_in=new_country)
print(country)
#Get register
countries = country_service.get_all()
print(countries)
The test suite is organized to validate all service components:
tests/
βββ conftest.py #test config
βββ test_climate_historical_climatology_service.py
βββ test_climate_historical_daily_service.py
βββ test_climate_historical_monthly_service.py
βββ test_mng_admin_1_service.py
βββ test_mng_admin_2_service.py
βββ test_mng_climate_measure_service.py
βββ test_mng_country_service.py
βββ test_mng_location_service.py
-
Service-Centric Testing:
- Each production service has a dedicated test file
- Tests validate both business logic and database interactions
-
Test Categories:
- Climate Services: Focus on temporal data operations
- Management Services: Validate CRUD operations for reference data
-
Configuration:
conftest.py
contains:- Database fixtures (in-memory SQLite)
- Mock configurations
- Shared test utilities
-
Testing Approach:
- 100% service layer coverage
- Integration-style tests with real database operations
- Mocking only for external dependencies
# Set up environment
python -m venv env
source env/bin/activate
# Install test dependencies
pip install pytest pytest-mock pytest-cov
# Run all tests
PYTHONPATH=$PYTHONPATH:./src pytest tests/
# Specific test examples:
pytest tests/test_climate_historical_daily_service.py -v # Run specific test file
pytest -k "test_get_daily_data" # Run tests matching pattern
Note
All tests use an isolated SQLite in-memory database configured in conftest.py, ensuring test independence and execution speed.
Our GitHub Actions pipeline implements a three-stage deployment process:
Code Push β Test Stage β Merge Stage β Release Stage
Purpose: Quality assurance
Trigger:
- Pushes to
stage
branch - New version tags (
v*
)
Key Actions: - Creates isolated Python 3.10 environment
- Installs dependencies + test packages
- Executes complete test suite against in-memory SQLite
- Generates coverage reports
- Enforces 100% service layer test coverage
Exit Criteria: All tests must pass before progression
Purpose: Stable code promotion
Dependencies: Requires Test Phase success
Automation:
- Auto-merges
stage
βmain
using branch protection rules - Validates no merge conflicts exist
- Maintains linear commit history
Purpose: Versioned artifact delivery
Key Processes:
-
Semantic Versioning:
- Analyzes commit history for version bump type
- Generates new
vX.Y.Z
tag - Updates
setup.py
version automatically
-
Artifact Packaging:
- Creates production-ready ZIP bundle
- Includes all runtime dependencies
-
Release Management:
- Publishes GitHub Release with changelog
- Attaches versioned binary asset
- Notifies stakeholders
Key Benefits:
- Zero-touch deployment from commit to production
- Enforced quality standards
- Traceable version history
- Automated semantic versioning
aclimate_v3_orm/
β
βββ .github/
β βββ workflows/ # CI/CD pipeline configurations
β
βββ src/
β βββ aclimate_v3_orm/
β βββ models/ # SQLAlchemy ORM models
β βββ schemas/ # Pydantic schemas for validation
β βββ services/ # Service layer for database operations
β βββ validations/ # Validation logic
β βββ enums/ # Application enumerations for type-safe fixed value sets
β βββ database/ # Database connection management
β
βββ tests/ # Test suite organized by service
βββ pyproject.toml # Package configuration
βββ requirements.txt # Package dependencies