Skip to main content

CityLearn

CityLearn is an open-source Gymnasium environment for building energy coordination, demand response and reinforcement learning. Use it to configure renewable energy communities, run controllers and compare energy, cost and service outcomes.

CityLearn v3 brings together buildings and thermal systems, PV, batteries, EVs and flexible loads with electrical limits, local energy sharing, changing members and assets, and data or equipment failures. It builds on the CityLearn community's work and the extensions developed by the Soft-CPS Research Group.

Documentation · Features · KPIs and scorecard · CityLearn UI

Install

python -m pip install citylearn

Use Python 3.9 or newer in a virtual environment. See the installation guide for setup and optional dependencies, including Parquet support.

Configure your community

CityLearn v3: configurable renewable energy communities with buildings, PV, storage, EVs, flexible loads, controllers, electrical limits, demand response and community KPIs.

The figure illustrates community configurations and services available in CityLearn. Individual scenarios can use different time resolutions; synchronized multi-community runs use a common timestep.

Run your first simulation

This example downloads a public dataset on first use, runs a short episode with the built-in business-as-usual controller and prints community KPIs. It works outside a repository checkout.

from citylearn.agents.baseline import BusinessAsUsualAgent
from citylearn.citylearn import CityLearnEnv

env = CityLearnEnv(
    "citylearn_challenge_2022_phase_all_plus_evs",
    episode_time_steps=24,
    interface="flat",
    render_mode="none",
)
agent = BusinessAsUsualAgent(env)
observations, info = env.reset(seed=0)
terminated = truncated = False

while not (terminated or truncated):
    actions = agent.predict(observations)
    observations, rewards, terminated, truncated, info = env.step(actions)

kpis = env.evaluate_v2()
selected = [
    "district_cost_total_control_eur",
    "district_energy_grid_total_import_control_kwh",
    "district_ev_performance_departure_min_acceptable_feasible_ratio",
    "district_electrical_service_phase_violations_energy_total_kwh",
]
print(kpis.loc[
    (kpis["level"] == "district") & kpis["cost_function"].isin(selected),
    ["cost_function", "value"],
].to_string(index=False))
env.close()

The first-simulation guide explains the loop, outputs and next steps. A runnable copy is in examples/first_simulation.py.

Learn more

Cite and contribute

See Publications and applications and Cite CityLearn for studies and the published reference. CityLearn is distributed under the MIT license; its development is supported by the project contributors.

Metadata

Release files for citylearn 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for citylearn 3.1.1
File Size Uploaded Provenance Actions
citylearn-3.1.1.tar.gz 722.6 kB Without provenance Details for citylearn-3.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for citylearn 3.1.1
File Interpreter ABI Platform Actions
citylearn-3.1.1-py3-none-any.whl Python 3 none any Details for citylearn-3.1.1-py3-none-any.whl

Total release size: 1.3 MB

Release files / citylearn-3.1.1.tar.gz

Download URL citylearn-3.1.1.tar.gz
Size 722.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3dcf316bb7c6615acb228107a8b728bbeb3f316f719d03a9ab50c164bb1a7f1d
BLAKE2b-256 checksum
How to use checksums
4fe2751a86ab27fd2fb3df5c73548c2aa01e3ae5e6450b77e6f2921da1a42c23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / citylearn-3.1.1-py3-none-any.whl

Download URL citylearn-3.1.1-py3-none-any.whl
Size 624.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fb9648f1f6fc839f38a8b5fe2c227b72d836829bed6aaac71a2c8c2db266f5f
BLAKE2b-256 checksum
How to use checksums
6519db8add6fd82d5dc49fc034212aca259b409a575bc7177945ebb932bafeca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Security for citylearn 3.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page