A fake sql database generator package
Project description
Data Structure Creation with sqlfaker
sqlfaker
is a python library that can be used to generate relational data structures and fill these structures with fake data.
Installation
sqlfaker
can be installed via pip from pypi.org. Just run the following command in your terminal or command prompt.
pip install sqlfaker
Class structure
This projet lets you define relational data structures that are build upon the concepts of Database
, Table
and Column
.
A Database
can have multiple Table
objects which again can each have multible Column
objects. There are two classes that inherit from the Column
class - ForeignKey
and PrimaryKey
. These allow you to create key colums.
Usage example
sqlfaker
can be used to generate a new database. So far, the Database
class only supports MySQL/MariaDB syntax (when it comes to SQL-Export). New database types will be implemented over time.
from sqlfaker.database import Database
# add database
my_db = Database(db_name="campusdb")
# add tables
my_db.add_table(table_name="student", n_rows=500)
my_db.add_table(table_name="studyprogram", n_rows=15)
sqlfaker
can be used to also specify the schema of the tables. This is supported by three methods: add_primary_key
, add_column
and add_foreign_key
. Depending on the type of column that should be created, the add methods need different parameters.
The order of column creation must follow consider their interdependencies (much like in SQL). If you e.g. create a foreign key column, you need to create the referenced primary key column first.
# add columns to studyprogram table
my_db.tables["studyprogram"].add_primary_key(column_name="studyprogram_id")
my_db.tables["studyprogram"].add_column(column_name="shortname", data_type="varchar(50)", data_target="name")
my_db.tables["studyprogram"].add_column(column_name="startdate", data_type="date", data_target="date")
# add columns to student table
my_db.tables["student"].add_primary_key(column_name="student_id")
my_db.tables["student"].add_column(column_name="firstname", data_type="varchar(50)", data_target="first_name")
my_db.tables["student"].add_column(column_name="lastname", data_type="varchar(50)", data_target="last_name")
my_db.tables["student"].add_foreign_key(column_name="studiengang_id", target_table="studiengang", target_column="studiengang_id")
As soon as the database structure has been defined, sqlfaker
can be used to generate data and then export the complete (or also parts of the) sql script to disk. The syntax of all generated SQL scripts follows MySQL/MariaDB.
data_target
is used to specify the type of fake data that is generated to fill the respective column.sqlfaker
uses Pythonfaker
for fake data generation. You can therefore reference allfaker
data types asdata target
. Seefaker
's documentation for more details.
my_db.generate_data()
my_db.export_sql("test.sql")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlfaker-0.5.tar.gz
.
File metadata
- Download URL: sqlfaker-0.5.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f41d0889c17a4d2a4233e050305901f1ca32b6b84a75c535d642ab8f7182815a |
|
MD5 | ba8215c169f07175ac374998e53cef05 |
|
BLAKE2b-256 | 5ceb4cb7df94300c064f028df4532eaabba92b04496afcf533fab7a7e0a6b7cb |
File details
Details for the file sqlfaker-0.5-py3-none-any.whl
.
File metadata
- Download URL: sqlfaker-0.5-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dca8209d3be0620240e24eff0aca5d8fd9876dd19b8baf4ec8c6a009afc0b71 |
|
MD5 | 5bf535e8bbec6f1bff8a7febd12e14d5 |
|
BLAKE2b-256 | b5569035a09eca405c38451d1be7ad4d5c44a333497ba30cd50f5078f10e851c |