Skip to main content

Eurlex Parser

This Python package fetches and parses data(regulations, directives and proposals) from Eurlex, the official website for European Union law. It extracts various parts of legal documents by their CELEX IDs and supports exporting the data in JSON and Pandas DataFrame formats.

Installation

pip install eurlex-parser

Usage

Functions

  • get_data_by_celex_id(celex_id: str, language: str = "en") -> dict: Fetches and parses the data for the given CELEX ID. Returns a dictionary with the document's title, preamble, articles, final part, and annexes.

  • get_json_by_celex_id(celex_id: str) -> str: Fetches and parses the data for the given CELEX ID and returns it in JSON format.

  • get_articles_by_celex_id(celex_id: str) -> pd.DataFrame: Fetches and parses the articles for the given CELEX ID and returns them as a Pandas DataFrame.

  • get_summary_by_celex_id(celex_id: str, language: str = "en") -> dict: Fetches and parses the summary for the given CELEX ID and returns it as a dictionary containing the document's title, chapters, and the last modified date. (Note: The summary is not available for all documents.)

Examples

Following are some examples of how to use the functions to fetch and parse data from a CELEX ID. For example, the CELEX ID 32013R0575 corresponds to the following URL: https://eur-lex.europa.eu/legal-content/en/TXT/?uri=celex:32013R0575

  1. Fetch and print data for a given CELEX ID:

    from eurlex import get_data_by_celex_id
    
    data = get_data_by_celex_id('32013R0575')
    print(data)
    
  2. Save data as a JSON file:

    from eurlex import get_json_by_celex_id
    
    json_data = get_json_by_celex_id('32013R0575')
    with open('32013R0575.json', 'w', encoding='utf-8') as f:
        f.write(json_data)
    
  3. Load articles into a Pandas DataFrame:

    from eurlex import get_articles_by_celex_id
    
    df = get_articles_by_celex_id('32013R0575')
    print(df.head())
    
  4. Fetch and print summary for a given CELEX ID:

    from eurlex import get_summary_by_celex_id
    
    summary = get_summary_by_celex_id('32013R0575')
    print(summary)
    

You can find some generated JSON files in the examples directory.

Data Structure

The main data structure returned by get_data_by_celex_id is a dictionary with the following format:

{
  "title": "Document Title",
  "preamble": {
    "text": "Preamble text",
    "notes": [
      {
        "id": "1",
        "text": "Note text",
        "url": "https://eur-lex.europa.eu/...",
        "reference": null
      }
    ]
  },
  "articles": [
    {
      "id": "Article ID",
      "title": "Article Title",
      "text": "Article text",
      "metadata": {
        "parent_title1": "Parent Title 1",
        "parent_title2": "Parent Title 2",
      },
      "notes": [
        {
          "id": "1",
          "text": "Note text",
          "url": "https://eur-lex.europa.eu/...",
          "reference": null
        }
      ],
      "references": [
        "Directive ..../../..",
        "Regulation (EU) No .../....",
      ]
    }
  ],
  "notes": [
    {
      "id": "1",
      "text": "Note text",
      "url": "https://eur-lex.europa.eu/...",
      "reference": null
    }
  ],  
  "references": [
    "Directive ..../../..",
    "Regulation (EU) No .../....",
  ],
  "final_part": "Final part text",
  "annexes": [
    {
      "id": "Annex ID",
      "title": "Annex Title",
      "text": "Annex text",
      "table": "Markdown table text"
    }
  ],
  "summary": {
    "title": "Document Title",
    "chapters": {
      "Chapter Title 1": "Chapter content 1",
      "Chapter Title 2": "Chapter content 2"
    },
    "last_modified": "Last modified date"
  },
  "related_documents": {
    "modifies": [
      {
        "Relation": "Modifies",
        "Act": {
            "celex": "CELEX Number",
            "url": "https://eur-lex.europa.eu/..."
        },
        "Comment": "Addition",
        "Subdivision concerned": "Article number/paragraph",
        "From": "date",
        "To": "date"
      }
    ],
    "modified_by": [
      {
        "Relation": "Corrected by",
        "Act": {
            "celex": "CELEX Number",
            "url": "https://eur-lex.europa.eu/..."
        },
        "Comment": "",
        "Subdivision concerned": "Article number/paragraph",
        "From": "date",
        "To": "date"
      }
    ],
  }
}

Notes

  • The script currently supports fetching data in English (en) only.

License

This project is licensed under the MIT License.

Metadata

Release files for eurlex-parser 0.0.13

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

Source distribution (sdist)

Source distribution for eurlex-parser 0.0.13
File Size Uploaded
eurlex-parser-0.0.13.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eurlex-parser 0.0.13
File Interpreter ABI Platform
eurlex_parser-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 kB

Release files / eurlex-parser-0.0.13.tar.gz

Download URL eurlex-parser-0.0.13.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e5985797abc71e456255f35e4c21ab44231830cb9bef832f7e4298cd84dd9a91
BLAKE2b-256 checksum
How to use checksums
4d91c4f918f4fd0493daf9452d56ef2bd44ebb8ce7f856ff357cdb801287c34a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.7

Release files / eurlex_parser-0.0.13-py3-none-any.whl

Download URL eurlex_parser-0.0.13-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94d0a4c84fdf17de6378a26b95492a5e19cc343efc2e2fdae076c36aad52ae1d
BLAKE2b-256 checksum
How to use checksums
e36144fc44f68f9047d28f948560acac8163e4fd13fbf11c0f88a04dda4b0092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.7

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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