A Python package for defining type-safe, dynamic, and maintainable Firestore schemas using Pydantic
Project description
Pydantic Fire
A Python package for defining type-safe, dynamic, and maintainable Firestore schemas using Pydantic.
✨ Features
- Type Safety: Full type hints and Pydantic validation
- Firestore Integration: Seamless Google Cloud Firestore integration
- Async Support: Full async/await support for modern Python applications
- Schema Management: Automatic schema validation and management
- Testing Tools: Built-in testing utilities and mock clients
- Documentation: Auto-generated documentation from your schemas
- Security Rules: Automatic Firestore security rules generation
- Performance: Optimized for high-performance applications
🚀 Quick Start
Installation
pip install pydantic-fire
Basic Usage
from pydantic_fire import Document, Collection, Field
from datetime import datetime
class UserDocument(Document):
name: str = Field(..., description="User's full name")
email: str = Field(..., description="User's email address")
created_at: datetime = Field(default_factory=datetime.utcnow)
is_active: bool = Field(default=True)
# Create a collection
UsersCollection = Collection(UserDocument, "users")
# Use with Firestore
from pydantic_fire import FirestoreGateway
gateway = FirestoreGateway()
user = UserDocument(name="John Doe", email="john@example.com")
result = gateway.create(UsersCollection, "user123", user)
Async Usage
import asyncio
from pydantic_fire import AsyncFirestoreGateway
async def main():
gateway = AsyncFirestoreGateway()
user = UserDocument(name="Jane Doe", email="jane@example.com")
result = await gateway.create_async(UsersCollection, "user456", user)
asyncio.run(main())
📖 Documentation
🏗️ Architecture
pydantic-fire/
├── core/ # Core schema and validation
├── gateway/ # Firestore gateway implementations
├── async_operations/ # Async operations support
├── utils/ # Utilities and helpers
├── tests/ # Test suite
└── templates/ # Code generation templates
🧪 Development
Setup Development Environment
git clone https://github.com/yourusername/pydantic-fire.git
cd pydantic-fire
pip install -r requirements-dev.txt
pip install -e .
Running Tests
pytest
Code Quality
make lint # Run linting
make format # Format code
make type-check # Type checking
Building Documentation
make docs-serve # Serve documentation locally
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Ensure tests pass (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📊 Requirements
- Python 3.8+
- Google Cloud Firestore
- Pydantic 1.10+ or 2.0+
🔧 Configuration
Environment Variables
export GOOGLE_APPLICATION_CREDENTIALS="path/to/service-account.json"
export FIRESTORE_EMULATOR_HOST="localhost:8080" # For local development
Configuration File
# config.py
from pydantic_fire import FirestoreGateway
# Configure gateway
gateway = FirestoreGateway(
project_id="your-project-id",
database="(default)"
)
📈 Performance
- Lazy Loading: Documents are loaded on-demand
- Batch Operations: Efficient bulk operations
- Caching: Built-in caching for frequently accessed data
- Connection Pooling: Optimized connection management
🔒 Security
- Security Rules: Automatic security rules generation
- Validation: Comprehensive input validation
- Type Safety: Compile-time type checking
- Access Control: Fine-grained access control
🐛 Troubleshooting
Common Issues
- Import Errors: Ensure all dependencies are installed
- Authentication: Check Google Cloud credentials
- Network Issues: Verify Firestore connectivity
- Type Errors: Check Pydantic model definitions
Getting Help
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Pydantic for data validation
- Google Cloud Firestore for database
- pytest for testing framework
Made with ❤️ by the pydantic-fire team
Project details
Release history Release notifications | RSS feed
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 pydantic_fire-1.0.0.tar.gz.
File metadata
- Download URL: pydantic_fire-1.0.0.tar.gz
- Upload date:
- Size: 79.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b1ed54dba8c0801dd599f7a8c40922d0a5b65dd48905eed3f8e78bb43f8a370
|
|
| MD5 |
5b96b244e7b7e91b9f968b1a8d013277
|
|
| BLAKE2b-256 |
e23c5d6d8740d9b3c1a43deeff22d0ca0324563daa9f32fd06467368547e4d65
|
File details
Details for the file pydantic_fire-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_fire-1.0.0-py3-none-any.whl
- Upload date:
- Size: 93.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c34bab88c7f6f367632c018ef952e99fa0ae1361f951364ba97aa57f399ce6e3
|
|
| MD5 |
bdff2009d61700c18480b3be773785b9
|
|
| BLAKE2b-256 |
b31c91066c8a65ec08fb7761b0b74c060adc4912fdd50f747112af50ee7bd50a
|