eu-consultations: A Python package for scraping textual data from EU public consultations
eu-consultations allows to scrape textual data from EU public consultation from https://ec.europa.eu/info/law/better-regulation. It's aim is to facilitate academic analysis of how the public participates in EU public consultations. In EU public consultations, the broader public of the EU is asked to supply input to proposed regulations.
The package has three main functions:
- Scrape metadata on feedback by the public to EU consultations by topic and/ or text search (in title and description of consultations) through accessing the API supplying the frontend to https://ec.europa.eu/info/law/better-regulation.
- Download files (e.g. .pdf and .docx) attached to feedback
- Extract text from files using docling
Downloaded data is validated and stored as JSON.
eu-consultationsis partially based on https://github.com/desrist/AskThePublic.
Installation
⚠️
eu-consultationsrequires Python 3.12 or higher.
eu-consultations is available through PyPI:
pip install eu-consultations
How to use eu-consultations
The following describes the typical pipeline for using eu-consultations:
1) Get consultation data
Here we will scrape data on consultations with the text "cloud" and "parrot" for the topic "DIGITAL". To get an overview over all possible topics, use:
from eu_consultations.scrape import show_available_topics
show_available_topics()
Now let's scrape all metadata on feedback to consultations on the the topic "DIGITAL" (Digital economy and society), where the search terms "cloud" or "parrot" appear.
from eu_consultations.scrape import scrape
initiatives_data = scrape(
topic_list=["DIGITAL"],
text_list=["cloud","parrot"],
max_pages=None, # restrict number of frontend pages to crawl
max_feedback = None, # set a maximum number of feedback to gather
output_folder=<my-folder>,
filename="<my-filename>.json")
This:
- serializes all data to .json in
- returns a list of
eu_consultations.consultation_data.Initiativedataclass objects, which store feedback data per consultation
2) Download files attached to consultation feedback
Using our previous initial scrape, we can now download all attached files to feedback if we want to:
from eu_consultations.extract_filetext import download_consultation_files
data_with_downloads = download_consultation_files(
initiatives_data = initiatives_data,
output_folder=<my-folder>)
This:
- downloads all attached files to /files
- returns a list of
eu_consultations.consultation_data.Initiativedataclass objects with file locations attached
3) Extract texts
A lot of feedback to consultations already contains text on the opinions of the consulted available through step 1), but much of it is also contained in attached document. Let's extract the text and attach to our data:
from eu_consultations.extract_filetext import extract_text_from_attachments
data_with_extracted_text = extract_text_from_attachments(
initiatives_data_with_attachments = data_with_downloads, #created in step 2)
stream_out_folder = <my-folder>/files #let's stream out to the same location as files
)
This:
- extracts text from all files referenced in
data_with_downloads - stores extracted text in lossless Docling JSON format per document at the folder set by stream_out_folder in a sub-directory
docling/and per consultation at a sub-directoryconsultations/ - returns a list of
eu_consultations.consultation_data.Initiativedataclass objects with text and docling JSON attached.
We can save the object, but be aware, it might be quite large:
from eu_consultations.scrape import save_to_json
save_to_json(data_with_extracted_text,
<my-folder>,
filename="initiatives_with_extracted.json")
Load serialized consultation data
If you have exported output from any of the above steps using eu_consultations.scrape.save_to_json, you can re-import into a list of eu_consultations.consultation_data.Initiative objects with eu_consultations.scrape.read_initiatives_from_json.
Development
The package is developed using uv. Run tests (using pytest) with:
uv run pytest --capture no
The --capture no setting will show loguru log output. It is not necessary.
Some tests need a working internet connection and scrape small amounts of data from https://ec.europa.eu/info/law/better-regulation.
Metadata
Release files for eu-consultations 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| eu_consultations-0.4.0.tar.gz | 13.0 kB | Without provenance | Details for eu_consultations-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eu_consultations-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for eu_consultations-0.4.0-py3-none-any.whl |
Total release size: 23.9 kB
Release files / eu_consultations-0.4.0.tar.gz
| Download URL | eu_consultations-0.4.0.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bdb75145eb92e3bad426f5dc8f04652dd4ae64b816b9d4b4572849194b81c3e0
|
|
BLAKE2b-256 checksum How to use checksums |
065fb91f9ef354915b583e5d3f6e6e024a7012a3b80b854b63122758af10f552
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / eu_consultations-0.4.0-py3-none-any.whl
| Download URL | eu_consultations-0.4.0-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4b01fd7a26a7e38678ea37c876ba5cdcfc6a21da0984ac7586be838ea526c93
|
|
BLAKE2b-256 checksum How to use checksums |
6728256ac7a545cd2b42cbb25cd0da4a095cff6e77e9929b187c170a5adf3b5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for eu-consultations 0.4.0
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.