Git Product home page Git Product logo

django-bulk-copy's Introduction

Django Bulk Copy ๐Ÿš€

License: MIT pre-commit.ci status GitHub contributors

PyPI PyPI - Python Version PyPI - Downloads PyPI - Format PyPI - Status PyPI - Implementation PyPI - Wheel

Poetry Black Mypy isort bandit

Create your mass data in a faster way with the COPY command.

โš ๏ธ Currently it supports only the Postgresql database. โš ๏ธ

Install ๐Ÿ› ๏ธ

pip install django-bulk-copy

Usage ๐Ÿš€

class TestModel(models.Model):
    integer_field = models.IntegerField(null=True)
    char_field = models.CharField(max_length=32, null=True)
    boolean_field = models.BooleanField(default=False)
    datetime_field = models.DateTimeField(null=True)
    json_field = models.JSONField(null=True)
from bulk_copy import BulkCopy

objects = [
    TestModel(
        integer_field=i,
        char_field=str(i),
        boolean_field=bool(i % 2),
        datetime_field=timezone.now(),
        json_field={i: f"{i:>09}"},
    )
    for i in range(1000)
]

BulkCopy(objects)

BulkCopy only uses the initial time of the transaction if your model has a date/datetime field with auto_now=True.

Benchmark ๐Ÿ“Š

Object Count bulk_create BulkCopy
1.000 0.06 0.05
10.000 0.34 0.08
100.000 3.96 0.80
1.000.000 38.96 7.57

Additional Note ๐Ÿ“

If you need to create your models from a csv file, django-postgres-copy could be a better alternative.

django-bulk-copy's People

Contributors

ahmetveburak avatar dependabot[bot] avatar onuralpszr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-bulk-copy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.