Universal law information API client library
Project description
lawpy
Universal law information API client library.
Features
- Multi-country support: Access law APIs from multiple countries (currently Korea)
- Simple interface: Intuitive API design for easy integration
- Type-safe: Full type hints for better IDE support
- Well-tested: Comprehensive test coverage
Installation
pip install lawpy
Quick Start
Korean Law API
Set your API key (email ID) as an environment variable:
export LAWPY_API_KEY="your-email-id"
Or pass it directly:
from lawpy import KoreanLawClient
# Using environment variable
client = KoreanLawClient()
# Or pass api_key directly
client = KoreanLawClient(api_key="your-api-key")
Search for laws
laws = client.search_laws("민법", per_page=5)
for law in laws:
print(f"{law.law_name} (ID: {law.law_id})")
Get detailed law information
law_detail = client.get_law_detail(law_id="001706")
print(f"Law: {law_detail.law_name_korean}")
print(f"Ministry: {law_detail.ministry}")
print(f"Promulgation Date: {law_detail.promulgation_date}")
print(f"Enforcement Date: {law_detail.enforcement_date}")
# Access articles
for article in law_detail.articles[:3]:
print(f"Article {article.number}: {article.title}")
for paragraph in article.paragraphs:
print(f" {paragraph.content}")
Get specific article
law_detail = client.get_law_detail(law_id="001706", article_number=1)
Get law by MST (master number)
law_detail = client.get_law_detail(mst=123456)
Get original text
law_detail = client.get_law_detail(law_id="001706", language="ORI")
Get current law list
laws = client.get_law_list(per_page=10)
for law in laws:
print(f"{law.law_name} (Effective: {law.enforcement_date})")
Get law amendment history
history = client.get_law_history(query="민법", per_page=10)
for h in history:
print(f"{h.law_name} ({h.promulgation_date})")
Get detailed law history
history_detail = client.get_law_history_detail(mst=9094)
print(history_detail) # Returns HTML text
API Key
To use the Korean Law API, you need an API key:
- Visit Korean Law Open API
- Sign up and get your email ID as API key
- Set it as environment variable:
LAWPY_API_KEY
Development
# Clone repository
git clone https://github.com/statpan/lawpy.git
cd lawpy
# Install development dependencies
uv sync --extra dev
# Run tests
uv run pytest
# Run linting
uv run ruff check src/lawpy tests
uv run ruff format src/lawpy tests
# Type checking
uv run mypy src/lawpy
# Build package
uv build
Project Structure
lawpy/
├── src/lawpy/
│ ├── __init__.py
│ ├── client.py # Base client class
│ ├── exceptions.py # Exception definitions
│ ├── models.py # Data models
│ └── kr/ # Korean API modules
│ ├── __init__.py
│ ├── base.py # Base class for Korean clients
│ ├── client.py # Integrated Korean client
│ ├── law.py # Law (법령) APIs
│ └── README.md # Korean API documentation
└── tests/
└── test_kr.py # Korean API tests
Roadmap
- Add more countries (Japan, China, etc.)
- Implement all Korean Law API categories
- Add async support
- Add caching layer
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE for details.
Links
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lawpy-0.1.0.tar.gz.
File metadata
- Download URL: lawpy-0.1.0.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26edaf7e1918162632f94347c9b27b91108f089ee0a4c761f0978f733f5dfc89
|
|
| MD5 |
17c7c819ff6ecf4c5cf89e9df00bbf90
|
|
| BLAKE2b-256 |
18040cea42a68284d1f977e7d04db8516d56b94d9dda9df12a2f026affe1902a
|
File details
Details for the file lawpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lawpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64e2f67529495778038b9de7203cb3eea3c8a3549b4bc0518327af79df70febc
|
|
| MD5 |
4ad2fa6a8988a2eec2aad228d60ad651
|
|
| BLAKE2b-256 |
f8145731199f08d25f2916f3b12dbc803a4476ec0aa93328e8991db1122ec5e9
|