A FastAPI application that provides a REST API interface for CKAN dataset management, with support for bulk uploads and CRUD operations.
- CRUD operations for CKAN datasets
- Bulk upload support via CSV
- Field mapping for complex CKAN schemas
- Error handling and validation
- Environment-based configuration
- Python 3.8+
- Git
- CKAN instance with API access
- Clone the repository:
[email protected]:Prajna1999/ocds-ckan.git
cd ocds-ckan
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create a
.env
file in the project root:
CKAN_URL=http://your-ckan-instance/
CKAN_API_KEY=your-api-key
- Start the FastAPI server:
fastapi dev app/main.py
- Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /api/v1/datasets/
Content-Type: application/json
{
"title": "Dataset Title",
"owner_org": "organization-name",
...
}
GET /api/v1/datasets/{dataset_id}
PUT /api/v1/datasets/{dataset_id}
Content-Type: application/json
{
"title": "Updated Title",
...
}
DELETE /api/v1/datasets/{dataset_id}
POST /api/v1/datasets/bulk-upload/
Content-Type: multipart/form-data
file: your-csv-file.csv
Your CSV file should have the following headers mapping to CKAN fields:
tender/title,buyer/name,Fiscal Year,ocid,initiationType,tag,id,date,tender/id,...
Example row:
"Sample Tender","Organization Name|Department",2024,ocid-123,tender,planning,1,2024-01-01,tender-123,...
app/
├── __init__.py
├── main.py
├── config.py
├── dependencies.py
├── routers/
│ ├── __init__.py
│ └── dataset_router.py
├── crud/
│ ├── __init__.py
│ └── dataset.py
├── schemas/
│ ├── __init__.py
│ └── dataset.py
├── models/
│ └── __init__.py
├── external_services/
│ ├── __init__.py
│ └── ckan_client.py
└── utils/
├── __init__.py
├── field_mapper.py
└── name_formatter.py
fastapi==0.104.1
uvicorn==0.24.0
python-multipart==0.0.6
pandas==2.1.3
ckanapi==4.7
python-dotenv==1.0.0
pydantic==2.5.1
pydantic-settings==2.1.0
- Install development dependencies:
pip install pytest black isort flake8
- Run tests:
pytest tests/
- Format code:
black app/
isort app/
-
CKAN Connection Error
- Check if CKAN_URL is accessible
- Verify CKAN_API_KEY is valid
-
CSV Upload Errors
- Ensure CSV headers match the expected format
- Check for missing required fields
- Verify data types match schema
- 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
Distributed under the MIT License. See LICENSE
for more information.