Metadata-Version: 2.4
Name: law4devs
Version: 1.0.0
Summary: Official Python SDK for the Law4Devs EU Regulatory Compliance API
Project-URL: Homepage, https://law4devs.eu
Project-URL: Documentation, https://docs.law4devs.eu/sdks/python
Author-email: law4devs <sdk@law4devs.eu>
Maintainer-email: Sofiane Hamlaoui <contact@law4devs.eu>
License: MIT
License-File: LICENSE
Keywords: ai-act,compliance,cra,eu,gdpr,law4devs,nis2,regulatory
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# law4devs

Official Python SDK for the [Law4Devs](https://law4devs.eu) EU Regulatory Compliance API.

Access structured, developer-friendly data for EU regulations — GDPR, Cyber Resilience Act, NIS2, AI Act, and more.

## Installation

```bash
pip install law4devs
```

Python 3.9+ required. Zero runtime dependencies (stdlib urllib only).

## Quick Start

```python
from law4devs import Law4DevsClient

client = Law4DevsClient()

# List all frameworks
page = client.frameworks.list()
for fw in page:
    print(fw.slug, fw.name)

# Get framework detail
cra = client.frameworks.get("cra")
print(cra.name, cra.requirement_count)

# Fetch a specific article
article = client.articles.get("cra", 13)
print(article.title, article.content)
```

## Authentication

The public API tier does not require authentication. Authenticated tiers provide higher rate limits:

```python
client = Law4DevsClient(api_key="your-api-key")
```

## Resources

### Frameworks

```python
page = client.frameworks.list(page=1, per_page=10)
print(page.meta.total, page.meta.pages)

cra = client.frameworks.get("cra")

for fw in client.frameworks.iter():
    print(fw.slug)
```

### Articles

```python
page = client.articles.list("cra", per_page=20)
art = client.articles.get("cra", 13)
related = client.articles.related("cra", 13)

for art in client.articles.iter("cra"):
    print(art.article_number, art.title)
```

### Recitals

```python
page = client.recitals.list("cra")
recital = client.recitals.get("cra", 10)

for recital in client.recitals.iter("cra"):
    print(recital.recital_number, recital.content[:80])
```

### Requirements

```python
page = client.requirements.list()
page = client.requirements.list(framework_slug="cra")

for req in client.requirements.iter(framework_slug="cra"):
    print(req.requirement_type, req.requirement_text[:60])
```

### Compliance Deadlines

```python
page = client.compliance.deadlines()
page = client.compliance.deadlines(framework_slug="nis2")

for d in client.compliance.iter_deadlines(framework_slug="nis2"):
    print(d.deadline_date, d.description)
```

### Tags

```python
page = client.tags.list()
tag = client.tags.get("security")

for tag in client.tags.iter():
    print(tag.slug, tag.name)
```

### Annexes

```python
page = client.annexes.list("cra")
annex = client.annexes.get("cra", "I")

for annex in client.annexes.iter("cra"):
    print(annex.annex_number, annex.title)
```

### Search

```python
results = client.search.query("vulnerability reporting")
results = client.search.query("audit", framework="gdpr")
results = client.search.query("encryption", result_type="requirement")
```

## Auto-Pagination

All list resources support `iter()` which automatically fetches all pages:

```python
all_articles = list(client.articles.iter("cra"))

for art in client.articles.iter("cra", per_page=50):
    process(art)
```

## Error Handling

```python
from law4devs import Law4DevsClient, NotFoundError, RateLimitError, Law4DevsError

client = Law4DevsClient()

try:
    fw = client.frameworks.get("nonexistent")
except NotFoundError as e:
    print(f"Not found: {e} (status {e.status_code})")
except RateLimitError:
    print("Rate limited — slow down requests")
except Law4DevsError as e:
    print(f"API error: {e}")
```

### Exception Hierarchy

| Exception | HTTP Status | Description |
|-----------|-------------|-------------|
| `Law4DevsError` | any | Base exception |
| `NotFoundError` | 404 | Resource not found |
| `ValidationError` | 400 | Invalid request parameters |
| `RateLimitError` | 429 | Rate limit exceeded |
| `ServerError` | 5xx | Server-side error |

## Configuration

| Parameter | Default | Description |
|-----------|---------|-------------|
| `base_url` | `https://api.law4devs.eu/v1` | API base URL |
| `api_key` | `None` | API key for authenticated tiers |
| `timeout` | `30` | Request timeout in seconds |
| `max_retries` | `3` | Retries on 429/5xx with exponential backoff |

## Available Frameworks

| Slug | Name | CELEX | Status |
|------|------|-------|--------|
| `cra` | Cyber Resilience Act | 32024R2847 | active |
| `nis2` | NIS2 Directive | 32022L2555 | active |
| `dora` | Digital Operational Resilience Act | 32022R2554 | active |
| `gdpr` | General Data Protection Regulation | 32016R0679 | active |
| `ai_act` | AI Act | 32024R1689 | active |
| `eidas` | eIDAS Regulation | 32014R0910 | active |
| `dsa` | Digital Services Act | 32022R2065 | active |
| `dma` | Digital Markets Act | 32022R1925 | active |
| `data_act` | Data Act | 32023R2854 | active |
| `dga` | Data Governance Act | 32022R0868 | active |
| `eidas2` | European Digital Identity Regulation | 32024R1183 | active |
| `cer` | Critical Entities Resilience Directive | 32022L2557 | active |
| `psd2` | Payment Services Directive 2 | 32015L2366 | active |
| `mica` | Markets in Crypto-Assets Regulation | 32023R1114 | active |
| `cybersecurity_act` | Cybersecurity Act | 32019R0881 | active |
| `eprivacy` | ePrivacy Directive | 32002L0058 | active |
| `red` | Radio Equipment Directive | 32014L0053 | active |
| `csrd` | Corporate Sustainability Reporting Dir. | 32022L2464 | active |
| `nis1` | NIS Directive (Original) | 32016L1148 | superseded |


## License

MIT License. See [LICENSE](LICENSE) for details.

## Links

- [Law4Devs API](https://law4devs.eu)
- [API Reference](https://docs.law4devs.eu)
- [PyPI](https://pypi.org/project/law4devs/)
