Skip to main content

Useful library

Project description

rn3: Python tools to help manage EEA Reportnet3

This repository contains tools to ineract with Reportnet3.

Requirements

  • Windows or Linux operating system
  • Python x64 3.8 - 3.12

Installation

From PyPI:

pip install rn3

Use 1: Generate Microsoft SQL script to create data tables based on a dataset in Reportnet3

import rn3

ds = DatasetModel()
ds.from_url(
    dataset_id=20822,
    api_key="ApiKey 0123456-2789-yyyy-xxxx-zzzzz",
    base_url=r"https://sandbox-api.reportnet.europa.eu",
)
sql_cmd = ds.sql_cmd(database_name="EnergyCommunity", schema_name="annex_XXIV")

print(sql_cmd)

output:

USE [EnergyCommunity]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [annex_XXIV].[PaMs](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](500) NOT NULL,
	[TitleNational] [nvarchar](500) NULL,
	[IsGroup] [int] NOT NULL,
	[ListOfSinglePams] [nvarchar](500) NULL,
	[ShortDescription] [text] NOT NULL,
	[ReportNet3HistoricReleaseId] [int] NOT NULL,
CONSTRAINT [PK_PaMs] PRIMARY KEY CLUSTERED
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [annex_XXIV].[PaMs]  WITH NOCHECK ADD  CONSTRAINT [FK_PaMs_ReportNet3HistoricReleases] FOREIGN KEY([ReportNet3HistoricReleaseId])
REFERENCES [metadata].[ReportNet3HistoricReleases] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [annex_XXIV].[PaMs] CHECK CONSTRAINT [FK_PaMs_ReportNet3HistoricReleases]
GO

.
.
.

... for all tables in dataset

Use 2: Write Code List Tables and Reference Data to database

Export Reference Data to excel

import rn3
dsrd = rn3.DatasetReferenceData()
dsrd.from_xlsx(xlsx_filepath="~/Downloads/Reference Dataset - Reference data.xlsx")
dsrd.to_mssql("osprey", "EnergyCommunity", "annex_XXIV")

output

writing table: [annex_XXIV].[dict_Sector]
writing table: [annex_XXIV].[dict_Objectives]
writing table: [annex_XXIV].[dict_UnionPolicies]
writing table: [annex_XXIV].[dict_Dimensions]
writing table: [annex_XXIV].[dict_Currencies]

Export the Codelist to database

ds = rn3.DatasetModel()

ds.from_url(
    dataset_id=60425,
    api_key="ApiKey 7fee1baa-f8f9-49bf-a21b-227749c961d5",
    base_url=r"https://api.reportnet.europa.eu",
)
ds.sql_codelist_data("osprey", "EnergyCommunity", "annex_XXIV")

output

writing table: [annex_XXIV].[dict_IsGroup]
writing table: [annex_XXIV].[dict_GeographicalCoverage]
writing table: [annex_XXIV].[dict_GHGAffected]
writing table: [annex_XXIV].[dict_TypePolicyInstrument]
writing table: [annex_XXIV].[dict_UnionPolicy]
writing table: [annex_XXIV].[dict_PaMRelateAirQuality]
writing table: [annex_XXIV].[dict_StatusImplementation]
writing table: [annex_XXIV].[dict_ProjectionsScenario]
writing table: [annex_XXIV].[dict_partNDC]
writing table: [annex_XXIV].[dict_Type]
writing table: [annex_XXIV].[dict_PolicyImpacting]

Contributor note

Before commit, run pre-commit hook pip install pre-commit pre-commit run -a

Connect to DB using sqlalchmy and odbc

from sqlalchemy import create_engine

servername = "osprey"
dbname = "EnergyCommunity"
engine = create_engine('mssql+pyodbc://@' + servername + '/' + dbname + '?trusted_connection=yes&driver=ODBC Driver 17 for SQL Server')
conn = engine.connect()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rn3-0.0.13.tar.gz (138.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rn3-0.0.13-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file rn3-0.0.13.tar.gz.

File metadata

  • Download URL: rn3-0.0.13.tar.gz
  • Upload date:
  • Size: 138.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rn3-0.0.13.tar.gz
Algorithm Hash digest
SHA256 8b4d10b96dc6cccc81307857b4084cc672c9e0a3272e9d30ce3e2ca27e76efec
MD5 60838a9766613c1af405a0ccd9e197f0
BLAKE2b-256 9ed3f31ab9979f173e8d3ec1732f008cc5ad189761cf0db49884e15572b43fff

See more details on using hashes here.

File details

Details for the file rn3-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: rn3-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rn3-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 643f2520883229579188573e5eb32b6aa06e6ae13b471ab037e17f94fda5ea8e
MD5 90bd12171d6c52bd5b8202819e5448d2
BLAKE2b-256 839c7b34af83f7a65299098e1b2db33860cc840d70c516619b9d54998d14143d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page