Skip to main content

A simple mysql orm for python3

Project description


FlagBox - a simple mysql orm for python3

Functional overview

  • Model-Oriented operations
  • Basic CRUD
  • Operator query
  • Automatic safety escape
  • Deadlock retry


shell>pip install flagbox


from flagbox import Mysql

# Create a connection.Automatically create database(if it is not created)
db = Mysql('localhost', 'root', 'your-password', 'testdb1')

class Worker(db.Model):
    __table__ = 'worker'

    id = db.PrimaryKeyField()
    username = db.VarcharField(max_length=32, nullable=False, unique=True, default=None, comment="Worker's username")
    password = db.VarcharField(max_length=32, nullable=False, unique=False, default=None, comment="Worker's password")
    salary = db.FloatField(nullable=False, unique=False, default=0.0, comment="Worker's monthly salary")


# Insert
jack = Worker(username='Jack', password='JackSoHandsome', salary=3999.2)

mary = Worker()
mary.username = 'Mary'
mary.password = 'MarySoBeautiful'

# Get all and get the first
all_workers =
the_first_worker =

# Query by operators
rich_workers =>=3000.0).all()

# Complex query by operators & and |
worker_jack =
	((Worker.username == 'jack') & (Worker.password == 'JackSoHandsome')) | (Worker.salary=='3999.2')

# Order the rows
the_richest_worker =[-Worker.salary]).first()

# Use the result
for worker in all_workers:
	print('username:{} password:{} salary:{}'.format(worker.username, worker.password, worker.salary))
print('And the richest worker is {}'.format(the_richest_worker.username))

# Update one row
worker_jack.salary = 3000.0

# Delete one row


Currently supported MySQL fields

FlagBox Mysql
PrimaryKeyField NO
BooleanField BOOLEAN
IntField INT
BigIntField BIGINT
FloatField FLOAT
DoubleField DOUBLE
VarcharField VARCHAR
TextField TEXT

PrimaryKeyField must be defined as the primary key.A basic definition below

mydb = Mysql('localhost', 'root', 'your-passwd', 'your-database')
class ModelName(mydb.Model):
    __table__ = 'mytable'

    id = mydb.PrimaryKeyField()
    # Other fields...

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

FlagBox-0.21.tar.gz (8.2 kB view hashes)

Uploaded source

Built Distribution

FlagBox-0.21-py3-none-any.whl (8.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page