pypinindia-rs
A Rust library for Indian pincode lookup and geographical information.
What You Have
A complete Rust implementation of pypinindia with:
- ✅ Core library (
src/lib.rs,src/core.rs,src/models.rs,src/error.rs) - ✅ Comprehensive API matching Python version
- ✅ Example code (
examples/basic_usage.rs) - ✅ Documentation and README
- ✅ Apache 2.0 License
- ✅ Compiles successfully
Features
- Comprehensive Pincode Database: Complete Indian pincode data with office information
- Multiple Lookup Methods: Search by pincode, state, district, taluk, or office name
- Fast Lookups: Efficient data structures for quick queries
- Type-Safe API: Full Rust type safety with comprehensive error handling
- Zero Dependencies: Minimal dependency footprint (only csv, serde, thiserror)
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
1. Copy the Data File
2. Test the Library
# Run the example
PYPININDIA_DATA_FILE=All_India_pincode_data.csv
# Or test with a simple program
3. Run Quality Checks
# Format code
# Check for issues
# Build release
# Generate docs
Usage Examples
Basic Usage
use ;
Complete Pincode Lookup
use PincodeData;
let data = new?;
// Get complete information
let info = data.get_pincode_info?;
for office in info
// Quick lookups
let state = data.get_state?;
let district = data.get_district?;
let taluk = data.get_taluk?;
let offices = data.get_offices?;
Search Operations
use PincodeData;
let data = new?;
// Search by state
let delhi_pincodes = data.search_by_state;
println!;
// Search by district
let mumbai_pincodes = data.search_by_district;
println!;
// Search by taluk
let taluks = data.search_by_taluk;
// Search by office name (partial match)
let airport_offices = data.search_by_office;
// Get all states
let states = data.get_states;
println!;
// Get districts in a state
let districts = data.get_districts;
Statistics
use PincodeData;
let data = new?;
let stats = data.get_statistics;
println!;
println!;
println!;
// Get post office summary for a pincode
let summary = data.get_postoffice_summary?;
println!;
println!;
Error Handling
use ;
let data = new?;
match data.get_state
API Overview
Key Features Implemented
- ✅
get_pincode_info()- Complete pincode information - ✅
get_state(),get_district(),get_taluk(),get_offices() - ✅
search_by_state(),search_by_district(),search_by_taluk() - ✅
search_by_office()- Partial name matching - ✅
get_states(),get_districts(),get_unique_taluks() - ✅
get_statistics()- Dataset statistics - ✅
get_postoffice_summary()- Office type distribution - ✅ Comprehensive error handling
- ✅ Convenience functions with singleton pattern
Data Format
The library expects CSV data with the following columns:
pincode: 6-digit pincodeofficename: Name of the post officeofficetype: Type of office (S.O, B.O, H.O, etc.)Deliverystatus: Delivery status (Delivery, Non-Delivery)divisionname: Postal division nameregionname: Postal region namecirclename: Postal circle nametaluk: Taluk/Tehsil namedistrictname: District namestatename: State/Territory name
Publishing to crates.io
Prepare for Publishing
Before publishing to crates.io:
-
Check name availability: Visit https://crates.io/crates/pypinindia
- If taken, update the name in
Cargo.toml
- If taken, update the name in
-
Update Cargo.toml:
- Add your name and email
- Add your GitHub repository URL
-
Create crates.io account:
- Go to https://crates.io
- Sign in with GitHub
- Get API token from https://crates.io/me
-
Login:
# Paste your API token -
Dry run:
-
Publish:
See PUBLISHING_GUIDE.md for detailed instructions.
Differences from Python Version
- No pandas dependency - Uses native Rust data structures
- No async batch processing - Can be added if needed
- No CLI tool - Can be added with
clapcrate - Data file required - See PUBLISHING_GUIDE.md for bundling options
- Type safety - Compile-time guarantees vs runtime checks
Adding Missing Features
CLI Tool
Add to Cargo.toml:
[]
= { = "4.0", = ["derive"] }
Create src/bin/pypinindia.rs for CLI implementation.
Async Batch Processing
Add to Cargo.toml:
[]
= { = "1", = ["full"] }
= "1.7"
Fuzzy Search (like Python's suggest_states)
Add to Cargo.toml:
[]
= "0.10"
Project Structure
.
├── Cargo.toml # Package manifest
├── README.md # User documentation
├── LICENSE # Apache 2.0
├── PUBLISHING_GUIDE.md # Publishing instructions
├── src/
│ ├── lib.rs # Public API
│ ├── core.rs # Core functionality
│ ├── models.rs # Data structures
│ └── error.rs # Error types
└── examples/
└── basic_usage.rs # Example code
Building from Source
Running Tests
API Documentation
Full API documentation is available at docs.rs/pypinindia.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Acknowledgments
- Inspired by the Python pypinindia library
- India Post for providing the comprehensive pincode database
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.