Skip to main content

A Python package for defining type-safe, dynamic, and maintainable Firestore schemas using Pydantic

Project description

Pydantic Fire

PyPI version Python versions License: MIT

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.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for your changes
  5. Ensure tests pass (pytest)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. 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

  1. Import Errors: Ensure all dependencies are installed
  2. Authentication: Check Google Cloud credentials
  3. Network Issues: Verify Firestore connectivity
  4. Type Errors: Check Pydantic model definitions

Getting Help

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments


Made with ❤️ by the pydantic-fire team

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

pydantic_fire-1.0.0.tar.gz (79.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_fire-1.0.0-py3-none-any.whl (93.0 kB view details)

Uploaded Python 3

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

Hashes for pydantic_fire-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3b1ed54dba8c0801dd599f7a8c40922d0a5b65dd48905eed3f8e78bb43f8a370
MD5 5b96b244e7b7e91b9f968b1a8d013277
BLAKE2b-256 e23c5d6d8740d9b3c1a43deeff22d0ca0324563daa9f32fd06467368547e4d65

See more details on using hashes here.

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

Hashes for pydantic_fire-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c34bab88c7f6f367632c018ef952e99fa0ae1361f951364ba97aa57f399ce6e3
MD5 bdff2009d61700c18480b3be773785b9
BLAKE2b-256 b31c91066c8a65ec08fb7761b0b74c060adc4912fdd50f747112af50ee7bd50a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page