Skip to main content

Django Gyro

Project description

Django Gyro

A declarative system for importing and exporting CSV data with Django models. Django Gyro provides a clean, validation-rich way to map CSV columns to Django model fields with automatic foreign key resolution and intelligent data slicing capabilities.

Features

  • Declarative Import System: Define how CSV data maps to your Django models using simple class-based importers
  • Automatic Foreign Key Resolution: Intelligently resolves relationships between models during import
  • Data Slicing & Export: Export subsets of your data with complex relationships intact
  • Multi-tenant Support: Built-in support for multi-tenant architectures
  • Validation-Rich: Comprehensive validation during import/export operations
  • Progress Tracking: Built-in progress bars for long-running operations

Quick Start

Installation

pip install django-gyro

Basic Usage

1. Define Your Importers

# myapp/importers.py
from django_gyro import Importer
from myapp.models import Tenant, Shop, Customer, Product, Order

class TenantImporter(Importer):
    model = Tenant

    class Columns:
        pass

class ShopImporter(Importer):
    model = Shop

    class Columns:
        tenant = Tenant

class CustomerImporter(Importer):
    model = Customer

    class Columns:
        shop = Shop
        tenant = Tenant

2. Export Data

from django_gyro import DataSlicer, ImportJob

# Define what data to export
tenant = Tenant.objects.filter(id=1)
shops = Shop.objects.filter(tenant=tenant)
customers = Customer.objects.filter(shop__in=shops)

# Export to CSV files
DataSlicer.run(
    source=DataSlicer.Postgres(database_url),
    target=DataSlicer.File('/path/to/export/'),
    jobs=[
      ImportJob(model=Tenant, query=tenant),
      ImportJob(model=Shop, query=shops),
      ImportJob(model=Customer, query=customers),
   ],
)

3. Import Data

# Import from CSV files
DataSlicer.run(
    source=DataSlicer.File('/path/to/import/'),
    target=DataSlicer.Postgres(database_url),
    jobs=[
      ImportJob(model=Tenant),
      ImportJob(model=Shop),
      ImportJob(model=Customer),
    ],
)

Use Cases

  • Data Migration: Move data between environments while preserving relationships
  • Selective Exports: Export specific subsets of data for development or testing
  • Multi-tenant Data Management: Handle complex tenant-based data relationships
  • CSV Import/Export: Robust CSV handling with validation and error reporting

Documentation

For detailed documentation, examples, and advanced usage, see TECHNICAL_DESIGN.md.

Requirements

  • Python 3.8+
  • Django 3.2+
  • PostgreSQL (for DataSlicer operations)

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Support

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

django_gyro-0.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

django_gyro-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file django_gyro-0.1.0.tar.gz.

File metadata

  • Download URL: django_gyro-0.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.0 CPython/3.10.17 Linux/6.11.0-1015-azure

File hashes

Hashes for django_gyro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1586b4973d02890efe324ee3d4be8569563bbba0bf13e44695efc4fd81e7cccf
MD5 9ceba5804c11e763fdf63f9285495208
BLAKE2b-256 dd384aacd7e2e4a83a85e492a98dd4daf7ecde55b8f4b33b257560d3614b789b

See more details on using hashes here.

File details

Details for the file django_gyro-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_gyro-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.0 CPython/3.10.17 Linux/6.11.0-1015-azure

File hashes

Hashes for django_gyro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93fa0ca0cc8e11dc104191b11051d2fba41440c661dd2049d80c071e494183b5
MD5 dfdb0797aa88137b05232649279c81be
BLAKE2b-256 794fe55f9989be3e292cfe2af8ef681a0f688c7b7ef8850f4efeaf79175aa733

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