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
  • Sync Support: Full synchronous support for legacy Python applications
  • 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")

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
├── sync_operations/  # Synchronous operations
├── 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.1.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.1-py3-none-any.whl (93.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_fire-1.0.1.tar.gz.

File metadata

  • Download URL: pydantic_fire-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 57aa9c004e3b619c5ac03f39c8ab901e5b911766eb0ebd7ca315d8f1ea5cb642
MD5 8df5b84030289cb466f68e31456337d9
BLAKE2b-256 e1e714e0769c6fd61d0c57e993c2fa52ead21f3afb9c29df0f9eaecd80172d3f

See more details on using hashes here.

File details

Details for the file pydantic_fire-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pydantic_fire-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 efc200c4a95d3ef967c3df0ac6ce77ebefe6a169e45e8c64a264e7e0c5f0be86
MD5 b01749c7ee01edbc7870cb48f7bc746f
BLAKE2b-256 2016c014fc196418b63f7dbe0463dd9f104788b87327c8bebddfa395aed172ce

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