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.2.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.2-py3-none-any.whl (93.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_fire-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f3e67965fd7dd79c7ae4f7759e168ffcaea31728251a9fd2ec0185e9aaafb537
MD5 a8eb18d35de0d2134ae6abf985db43d7
BLAKE2b-256 cd1936509009d75f0fc09037e49aa052aa332a92526396c80881fdade907357a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydantic_fire-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90a9487ad6f368955e69b833e275e350195a6a1a9f2e01e80d6380bc2919e4fc
MD5 c6f5b5f1d60f498988af45d965ab32c5
BLAKE2b-256 0f69ca568ab70fd2575d1e83293f9c016f7956a7c9e3930240fc8b31f7afdc4d

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