{"id":29814482,"url":"https://github.com/dev360/django-gyro","last_synced_at":"2026-01-20T17:00:12.718Z","repository":{"id":301231648,"uuid":"1005119933","full_name":"dev360/django-gyro","owner":"dev360","description":"Django data slicer utility for import / export","archived":false,"fork":false,"pushed_at":"2025-07-14T13:01:56.000Z","size":264,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-02T14:22:12.286Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev360.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-19T17:45:18.000Z","updated_at":"2025-07-14T13:01:59.000Z","dependencies_parsed_at":"2025-06-25T20:44:37.480Z","dependency_job_id":null,"html_url":"https://github.com/dev360/django-gyro","commit_stats":null,"previous_names":["dev360/django-gyro"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/dev360/django-gyro","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev360%2Fdjango-gyro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev360%2Fdjango-gyro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev360%2Fdjango-gyro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev360%2Fdjango-gyro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev360","download_url":"https://codeload.github.com/dev360/django-gyro/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev360%2Fdjango-gyro/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-28T19:18:04.767Z","updated_at":"2026-01-20T17:00:12.693Z","avatar_url":"https://github.com/dev360.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Gyro\n\nA 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.\n\n## Features\n\n- **Declarative Import System**: Define how CSV data maps to your Django models using simple class-based importers\n- **Automatic Foreign Key Resolution**: Intelligently resolves relationships between models during import\n- **Circular Dependency Handling**: Automatically resolves circular relationships (e.g., Customer ↔ CustomerReferral)\n- **ID Remapping Strategies**: Multiple strategies for handling ID conflicts during imports\n- **Data Slicing \u0026 Export**: Export subsets of your data with complex relationships intact\n- **Multi-tenant Support**: Built-in support for multi-tenant architectures with tenant-aware remapping\n- **PostgreSQL Bulk Loading**: High-performance imports using PostgreSQL COPY operations\n- **Validation-Rich**: Comprehensive validation during import/export operations\n- **Progress Tracking**: Built-in progress bars for long-running operations\n\n## Quick Start\n\n### Installation\n\n```bash\npip install django-gyro\n```\n\n### Basic Usage\n\n#### 1. Define Your Importers\n\n```python\n# myapp/importers.py\nfrom django_gyro import Importer\nfrom myapp.models import Tenant, Shop, Customer, Product, Order\n\nclass TenantImporter(Importer):\n    model = Tenant\n\n    class Columns:\n        pass\n\nclass ShopImporter(Importer):\n    model = Shop\n\n    class Columns:\n        tenant = Tenant\n\nclass CustomerImporter(Importer):\n    model = Customer\n\n    class Columns:\n        shop = Shop\n        tenant = Tenant\n```\n\n#### 2. Export Data\n\n```python\nfrom django_gyro import DataSlicer, ImportJob\n\n# Define what data to export\ntenant = Tenant.objects.filter(id=1)\nshops = Shop.objects.filter(tenant=tenant)\ncustomers = Customer.objects.filter(shop__in=shops)\n\n# Export to CSV files\nDataSlicer.run(\n    source=DataSlicer.Postgres(database_url),\n    target=DataSlicer.File('/path/to/export/'),\n    jobs=[\n      ImportJob(model=Tenant, query=tenant),\n      ImportJob(model=Shop, query=shops),\n      ImportJob(model=Customer, query=customers),\n   ],\n)\n```\n\n#### 3. Import Data\n\n```python\n# Import from CSV files\nDataSlicer.run(\n    source=DataSlicer.File('/path/to/import/'),\n    target=DataSlicer.Postgres(database_url),\n    jobs=[\n      ImportJob(model=Tenant),\n      ImportJob(model=Shop),\n      ImportJob(model=Customer),\n    ],\n)\n```\n\n#### 4. Management Command for CSV Import\n\nDjango Gyro includes a management command for importing CSV data:\n\n```bash\n# Import CSV data with automatic ID remapping\npython manage.py import_csv_data --source-dir /path/to/csv/files/\n\n# Preview import without making changes\npython manage.py import_csv_data --source-dir /path/to/csv/files/ --dry-run\n\n# Use INSERT statements instead of PostgreSQL COPY (slower but more compatible)\npython manage.py import_csv_data --source-dir /path/to/csv/files/ --use-insert\n```\n\nThe command automatically handles dependency ordering and uses sequential ID remapping to avoid conflicts.\n\n#### 5. ID Remapping Strategies (Python API)\n\nFor more control over ID remapping, use the Python API:\n\n```python\nfrom django_gyro.importing import (\n    ImportContext,\n    SequentialRemappingStrategy,\n    HashBasedRemappingStrategy,\n    TenantAwareRemappingStrategy,\n    NoRemappingStrategy\n)\n\n# Sequential remapping (assigns new IDs starting from MAX+1)\nstrategy = SequentialRemappingStrategy(model=Customer)\ncontext = ImportContext(\n    source_directory=Path(\"/path/to/csv/files\"),\n    id_remapping_strategy=strategy\n)\n\n# Hash-based remapping (stable IDs using business keys)\nstrategy = HashBasedRemappingStrategy(\n    model=Customer,\n    business_key=\"email\"  # Use email to generate stable IDs\n)\n\n# Tenant-aware remapping (works with any \"tenant\" model name)\nstrategy = TenantAwareRemappingStrategy(\n    tenant_model=Organization,  # Your tenant model (any name)\n    tenant_mappings={1060: 10, 2000: 11}  # staging -\u003e local IDs\n)\n\n# Manual ID mappings\nid_mappings = {\n    \"myapp.Customer\": {100: 200, 101: 201},  # old_id: new_id\n    \"myapp.Order\": {500: 600, 501: 601}\n}\n```\n\n## Use Cases\n\n- **Data Migration**: Move data between environments while preserving relationships\n- **Selective Exports**: Export specific subsets of data for development or testing\n- **Multi-tenant Data Management**: Handle complex tenant-based data relationships\n- **CSV Import/Export**: Robust CSV handling with validation and error reporting\n\n## Documentation\n\nFor detailed documentation, examples, and advanced usage, see [TECHNICAL_DESIGN.md](docs/TECHNICAL_DESIGN.md).\n\n## Requirements\n\n- Python 3.8+\n- Django 3.2+\n- PostgreSQL (for DataSlicer operations)\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support\n\n- 📖 [Documentation](docs/TECHNICAL_DESIGN.md)\n- 🐛 [Issue Tracker](https://github.com/dev360/django-gyro/issues)\n- 💬 [Discussions](https://github.com/dev360/django-gyro/discussions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev360%2Fdjango-gyro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev360%2Fdjango-gyro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev360%2Fdjango-gyro/lists"}