Metadata-Version: 2.1
Name: eurlex-parser
Version: 0.0.2
Summary: Eurlex parser for fetching and parsing Eurlex data.
Home-page: https://github.com/noworneverev/eurlex-parser
Author: Yan-Ying Liao
Author-email: n9102125@gmail.com
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: requests ==2.32.3
Requires-Dist: bs4 ==0.0.2
Requires-Dist: lxml ==5.2.2
Requires-Dist: pandas ==2.2.2

# Eurlex Parser

This Python package fetches and parses data 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

```bash
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.


### 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:
    ```python
    from eurlex import get_data_by_celex_id

    data = get_data_by_celex_id('32013R0575')
    print(data)
    ```

2. Save data as a JSON file:
    ```python
    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:
    ```python
    from eurlex import get_articles_by_celex_id

    df = get_articles_by_celex_id('32013R0575')
    print(df.head())
    ```

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:
```json
{
  "title": "Document Title",
  "preamble": {
    "text": "Preamble text",
    "notes": [
      {
        "id": "1",
        "text": "Note text",
        "url": "https://eur-lex.europa.eu/..."
      }
    ]
  },
  "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/..."
        }
      ]
    }
  ],
  "final_part": "Final part text",
  "annexes": [
    {
      "id": "Annex ID",
      "title": "Annex Title",
      "text": "Annex text",
      "table": "Markdown table text"
    }
  ]
}
```

### Notes

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

## License

This project is licensed under the MIT License.
