OpenGovCorpus
A Python library for creating structured datasets and RAG embeddings from government websites.
Installation
We recommend using UV for fast, reliable package installation:
uv pip install opengovcorpus
Or with pip:
pip install opengovcorpus
Configuration
Setting Up API Keys
Create a configuration file to store your API credentials:
Location: ~/.opengovcorpus/config.json
{
"provider": "openai",
"api_key": "sk-your-api-key-here"
}
The library supports multiple embedding providers:
- OpenAI:
"provider": "openai" - Gemini:
"provider": "gemini" - Hugging Face:
"provider": "huggingface"
The library automatically reads this configuration file when generating embeddings.
Usage
Import the Library
import opengovcorpus as og
1. Create Dataset
Scrape a government website and create a structured knowledge graph with prompt-response pairs, automatically split into train/validation/test sets.
og.create_dataset(
name="uk", # Name of the dataset folder
url="https://data.gov.uk", # Government website to scrape
include_metadata=True, # Include metadata for each prompt-response pair
train_split=0.8, # 80% for training
val_split=0.1, # 10% for validation
test_split=0.1, # 10% for testing
max_pages=10 # Number of pages to scrape
)
Output Structure:
OpenGovCorpus-uk/
├── train.csv
├── valid.csv
└── test.csv
Each CSV contains structured prompt-response pairs suitable for fine-tuning or RAG applications.
2. Generate RAG Embeddings
Convert your dataset into vector embeddings for retrieval-augmented generation (RAG) applications.
og.create_rag_embeddings(
model="openai/text-embedding-3-large", # Embedding model
vector_db="chroma", # Vector database (Chroma by default)
config_path="~/.opengovcorpus/config.json" # Optional: Path to config file (defaults to ~/.opengovcorpus/config.json)
)
Note: The config_path parameter is optional. If not specified, it automatically uses the config file created in the Configuration section above (~/.opengovcorpus/config.json).
Supported Models:
- OpenAI:
openai/text-embedding-3-large,openai/text-embedding-3-small - Gemini:
gemini/text-embedding-004 - Hugging Face:
hf/sentence-transformers/all-MiniLM-L6-v2,hf/BAAI/bge-large-en-v1.5
How it works:
- Reads
train.csv,valid.csv, andtest.csvfrom your dataset - Converts prompts (and optionally responses) into vector embeddings
- Stores embeddings in the specified vector database (Chroma local storage by default)
- Enables efficient semantic search and retrieval for RAG applications
Complete Example
import opengovcorpus as og
# Step 1: Create dataset from government website
og.create_dataset(
name="uk-data",
url="https://data.gov.uk",
include_metadata=True,
train_split=0.8,
val_split=0.1,
test_split=0.1
)
# Step 2: Generate embeddings for RAG
og.create_rag_embeddings(
model="openai/text-embedding-3-large",
vector_db="chroma"
# config_path is optional - uses ~/.opengovcorpus/config.json by default
)
Features
- Automated Web Scraping: Extract structured data from government websites
- Knowledge Graph Creation: Convert scraped content into meaningful prompt-response pairs
- Dataset Splitting: Automatic train/validation/test split configuration
- Multi-Provider Support: Works with OpenAI, Gemini, and Hugging Face embeddings
- Vector Database Integration: Built-in Chroma support for local embedding storage
- RAG-Ready: Outputs are optimized for retrieval-augmented generation workflows
Use Cases
- Building government data chatbots
- Fine-tuning language models on official documentation
- Creating semantic search systems for public information
- Developing RAG applications for policy and regulation queries
- Generating training datasets for civic tech applications
Requirements
- Python 3.8+
- API key for your chosen embedding provider (OpenAI, Gemini, or Hugging Face)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Support
For issues, questions, or feature requests, please open an issue on the GitHub repository.
Metadata
Release files for opengovcorpus 0.1.4
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 |
|---|---|---|---|---|
| opengovcorpus-0.1.4.tar.gz | 20.5 kB | Without provenance | Details for opengovcorpus-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opengovcorpus-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for opengovcorpus-0.1.4-py3-none-any.whl |
Total release size: 37.6 kB
Release files / opengovcorpus-0.1.4.tar.gz
| Download URL | opengovcorpus-0.1.4.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69cfa05211696ad1e4e8f03a5f381b855bf734fa49bdd2e925d921e83d0a1b63
|
|
BLAKE2b-256 checksum How to use checksums |
f927c2ac7157b706fff5b8990664accc3735d92f795b76fcc80991bc349e3b85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / opengovcorpus-0.1.4-py3-none-any.whl
| Download URL | opengovcorpus-0.1.4-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b870e9d5715f7679d68a01f993f0d302057285c347418a16fb2bd0e787df23b2
|
|
BLAKE2b-256 checksum How to use checksums |
ed9c93a70cebc57177dbe7630c2a9f080a6ee49f5224e1f00111a04fada5bfb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Security for opengovcorpus 0.1.4
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.