Skip to main content

Pydantic validators for mySociety democracy types

Project description

mysoc-validator

A set of pydantic-based validators and classes for common mySociety democracy formats.

Currently supports:

  • Popolo database
  • Transcript format
  • Interests format

XML based formats are tested to round-trip with themselves, but not to be string identical with the original source.

Can be installed with pip install mysoc-validator

To use as a cli validator:

python -m mysoc_validator validate --path <path-to-people.json> --type popolo
python -m mysoc_validator validate --path <path-to-transcript.xml> --type transcript
python -m mysoc_validator validate --path <path-to-interests.xml> --type interests

Or if using uvx (don't need to install first):

uvx mysoc-validator validate --path <path-to-people.json> --type popolo

Popolo

A pydantic based validator for main mySociety people.json file (which mostly follows the popolo standard with a few extra bits).

Validates:

  • Basic structure
  • Unique IDs and ID Patterns
  • Foreign key relationships between objects.

It also has support for looking up from name or identifying to person, and new ID generation for membership.

Using name or ID lookup

After first use, there is some caching behind the scenes to speed this up.

from mysoc_validator import Popolo
from mysoc_validator.models.popolo import Chamber, IdentifierScheme
from datetime import date

popolo = Popolo.from_parlparse()

keir_starmer_parl_id = popolo.persons.from_identifier(
    "4514", scheme=IdentifierScheme.MNIS
)
keir_starmer_name = popolo.persons.from_name(
    "keir starmer", chamber_id=Chamber.COMMONS, date=date.fromisoformat("2022-07-31")
)

keir_starmer_parl_id.id == keir_starmer_name.id

Transcripts

Python validator and handler for 'publicwhip' style transcript format.

from mysoc_validator import Transcript
from pathlib import Path

transcript_file = Path("data", "debates2023-03-28d.xml")

transcript = Transcript.from_xml_path(transcript_file)

Register of Interests

Python validator and handler for 'publicwhip' style interests format.

from mysoc_validator import Register
from pathlib import Path

register_file = Path("data", "regmem2024-05-28.xml")
interests = Register.from_xml_path(register_file)

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

mysoc_validator-0.3.2.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

mysoc_validator-0.3.2-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file mysoc_validator-0.3.2.tar.gz.

File metadata

  • Download URL: mysoc_validator-0.3.2.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for mysoc_validator-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f31375036eeea29ec7908f2d051290ce3e41e05a67520360f1c8023f4414f0be
MD5 0c25614d64ad8552f393a1758623a7ae
BLAKE2b-256 7342929715cda1024d3ee4cb0e811d62b6eb205e393b3e78f127b7b1d01d0b14

See more details on using hashes here.

File details

Details for the file mysoc_validator-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mysoc_validator-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c61784d430a6071299c3f785d44fbfca3a1a7fc6fa00e703356a90283b4b72f
MD5 3acdbeb1a968484a095c601996d52f2a
BLAKE2b-256 2bc5f6b48ecc32c74fa235c4bb53c4ef7e23797d7dd16f2c41fc1c7e4df84ac1

See more details on using hashes here.

Supported by

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