• Stars
    star
    233
  • Rank 165,991 (Top 4 %)
  • Language
    Python
  • Created about 12 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A small, schemaless Python ORM that is backed by SQLite. ⛺

Description

Build Status Code Shelter

goatfish is a small, schemaless ORM that is backed by SQLite.

It's also this:

A goatfish

Its usage is very simple, just have your classes inherit from goatfish.Model and and specify a connection, and the goatfish methods are available to you. goatfish also supports querying for arbitrary properties in your models, as well as indexing on arbitrary properties. It does not enforce a schema of any kind.

It appears that this method is identical to what FriendFeed used to implement a schemaless layer over MySQL, which is pretty significant validation:

http://backchannel.org/blog/friendfeed-schemaless-mysql

Usage

To use goatfish, all you need to do is create a class that inherits from goatfish.Model:

import goatfish
import sqlite3

db_connection = sqlite3.connect(":memory:")

class Test(goatfish.Model):
    class Meta:
        # This is so we know where to connect.
        connection = db_connection
        indexes = (
            ("foo",), # Index on just `foo`.
            ("foo", "bar"), # Index on both `foo` and `bar`, together.
        )

# Create the necessary tables. If they exist, do nothing.
Test.initialize()

foo = Test()
foo.foo = "hi"
foo.bar = "hello"
foo.save()

# Retrieve all elements.
>>> [test.bar for test in Test.all()]
['hello']

# Count the number of elements.
>>> Test.count(foo="hi")
1

# Run a query with parameters (slow, loads every item from the DB to check it).
>>> [test.bar for test in Test.find(bar="hello")]
['hello']

# This uses an index, so it's fast.
>>> [test.foo for test in Test.find(foo="hi"})]
['hi']

# Fast, because there's an index for when both fields are used together.
>>> [test.bar for test in Test.find(foo="hi", bar="hello")]
['hello']

# Run a query with a parameter that doesn't exist in the dataset.
>>> [test.bar for test in Test.find({bar="hello", baz="hi"})]
[]

>>> Test.find_one(bar="hello").foo
"hi"

>>> print(Test.find_one(bar="doesn't exist"))
None

# Delete the element.
>>> foo.delete()

# Try to retrieve all elements again.
>>> [test.bar for test in Test.find()]
[]

Indexes

What sets goatfish apart from other modules such as shelve, zodb, etc is its ability to query random attributes, and make those queries faster by using SQLite indexes.

The way this is achieved is by creating an intermediate table for each index we specify. The index tables consist of the uuid column, and one column for every field in the index. This way, we can store the value itself in these index tables and query them quickly, as the rows have SQLite indexes themselves.

The find() method uses these indexes automatically, if they exist, to avoid sequential scans. It will automatically use the largest index that contains the data we want to query on, so a query of {"foo": 3, "bar": 2} when only foo is indexed will use the index on foo to return the data, and do a sequential scan to match bar.

Right now, new indexes are only populated with data on save(), so you might miss rows when querying on indexes that are not ready yet. To populate indexes, go through the objects in your model and perform a save() in each of them. Convenience functions to populate single indexes will be provided shortly.

Installation

To install goatfish you need:

  • Python 3.4 or later.

You have multiple options for installation:

License

goatfish is distributed under the BSD license.

More Repositories

1

catt

Cast All The Things allows you to send videos from many, many online sources to your Chromecast.
Python
3,257
star
2

shortuuid

A generator library for concise, unambiguous and URL-safe UUIDs.
Python
1,905
star
3

django-annoying

A django application that tries to eliminate annoying things in the Django framework. ⛺
Python
917
star
4

expounder

A library for explaining things in HTML.
JavaScript
504
star
5

tbvaccine

A small utility to pretty-print Python tracebacks. ⛺
Python
376
star
6

django-loginas

"Log in as user" for the Django admin.
Python
355
star
7

python-yeelight

A Python library for controlling YeeLight WiFi RGB bulbs (mirror of https://gitlab.com/stavros/python-yeelight).
Python
262
star
8

netproxy

A Netflix/Hulu/Pandora/etc proxy in a box.
Python
230
star
9

python-fuse-sample

A sample FUSE filesystem in Python.
Python
169
star
10

django-project-template

The Django project template I use, for installation with django-admin.
Python
161
star
11

gr8w8upd8m8

Gr8W8Upd8M8 is a script to automatically read your weight from a Wii Balance Board. ⛺
Python
145
star
12

imdbapi

An API for the IMDB site. ⛺
Python
131
star
13

A6lib

An ESP8266/Arduino library for communicating with the A6 GSM module. ⛺
C++
127
star
14

jsane

A saner way to traverse JSON in Python
Python
125
star
15

encbup

Encrypted backups (without the backups)
Python
121
star
16

sysaidmin

A GPT-powered sysadmin.
Python
115
star
17

tiny-ESP8266-breakout

A very small and basic ESP8266 breakout board
110
star
18

omnisync

omnisync is a universal file synchroniser and backup program (think rsync) that supports multiple transport systems (such as plain files, sftp, s3 and virtual, currently, and support for ftp, http, et al is planned). It is designed to be fast, small, extensible, portable and bandwidth-efficient. It is available for Linux, Windows and Mac. ⛺
Python
87
star
19

iRotary

One man's quest to turn an old rotary phone into a mobile phone.
Arduino
83
star
20

django-cloudflare-push

A piece of middleware that uses Cloudflare's HTTP/2 Push to push static media to the clients. ⛺
Python
75
star
21

gweet

A message queue for the abhorrently named Internet of Things
Go
70
star
22

static-appengine-hoster

An App Engine application for hosting static sites under multiple domains in a single app.
Python
66
star
23

django-tokenauth

Django authentication backend that uses tokens sent over email.
Python
63
star
24

arduino-irrigation

A GSM-based Arduino remote controller for an irrigation system.
Arduino
62
star
25

esplights

A home automation sensor and controller based on an ESP8266.
Arduino
48
star
26

yeecli

A command-line utility for a YeeLight RGB lamp. (mirror of https://gitlab.com/stavros/yeecli)
Python
42
star
27

episode-renamer

Episode renamer is a simple python script that renames folders of TV episode video files to their proper names.
Python
41
star
28

kicad-lib

My KiCad components library.
35
star
29

Spamnesty

A service that tries to have some fun with spam (mirror of https://gitlab.com/stavros/Spamnesty/)
Python
33
star
30

captainwebhook

Captain Webhook eats webhooks and executes commands.
Python
30
star
31

spamgpt

SpamGPT, a bot that wastes spammers' damn time, like they waste mine.
Python
25
star
32

pastebinit

pastebinit is a command-line tool to send data to a "pastebin", a web site which allows its users to upload snippets of text for public viewing. ⛺
Python
25
star
33

apache-config

A script for configuring apache with Django+wsgi/fcgi+virtualenv+etc.
Python
23
star
34

ArduiRC

Remotely control IR/RF devices from a computer with Arduino.
Arduino
18
star
35

docker-fgallery

A Dockerfile for installing fgallery. ⛺
Shell
18
star
36

ez-openai

Ez API, ez life.
Python
16
star
37

landing-page

A very simple landing page app for AppEngine.
Python
15
star
38

stringphone

String phone is a secure communications protocol and library geared towards embedded devices.
Python
14
star
39

bakeit

A command-line utility for pastery, the best pastebin in the world.
Python
12
star
40

pythess-files

The code files/presentations/everything else used in the PyThess meetup
Jupyter Notebook
11
star
41

lektor-shortcodes

A shortcodes plugin for lektor
Python
11
star
42

shufflecast

A TV channel with all your favorite shows.
Python
11
star
43

photocopy

A script to archive photos off a camera to a directory.
Python
10
star
44

nxt-python

NXT-Python is a python driver/interface for the Lego Mindstorms NXT robot based on NXT_python.
Python
10
star
45

Reverend

A clone of Reverend, the naive Bayesian classifier written in Python.
Python
10
star
46

A6-ESP8266-breakout

A breakout board that includes an ESP8266 and an A6 GSM module, for easily making GSM-enabled applications (mirror)
Shell
9
star
47

Pythia

High quality & fast "true random" number generator (shuffling system)
JavaScript
9
star
48

lektor-thumbnail-generator

A thumbnail generator for Lektor content
Python
9
star
49

pastery.vim

A Vim plugin for the sweetest pastebin in the world, pastery.net.
Vim Script
9
star
50

apt-btrfs-snapshot

A fork of apt-btrfs-snapshot.
Python
8
star
51

gamelights

An RGB LED strip WiFi controller, complete with code and PCB designs.
KiCad Layout
8
star
52

mediacenter-in-a-box

A media center in a box, compatible with Harbormaster for one-line deployments.
Python
8
star
53

pylast

A clone of Amr Hassan's pylast: a python interface to last.fm (and other api-compatible websites)
Python
6
star
54

awesomeblog-club

An easily self hostable curation site for collecting blogs and links.
TypeScript
5
star
55

django-project-templates

Some Django project templates for various things.
4
star
56

requests-guard

requests-guard is a small library that allows you to impose size and time limits on your HTTP requests.
Python
4
star
57

ChatGPT-Bot

A small Python library that makes it easier to write a ChatGPT bot.
Python
4
star
58

rust-bakeit

A command-line client for pastery.net, the best pastebin in the world (official mirror of https://gitlab.com/stavros/rust-bakeit).
Rust
3
star
59

the-spam-chronicles

The Spam Chronicles, a static website where I post all the spam I got and SpamGPT auto-replied to.
Python
2
star
60

progress

A simple progress bar in Python
Python
2
star
61

blacklist-pre-commit-hook

A pre-commit hook for blacklisting certain functions
Python
2
star
62

back-scratcher

A back scratching robot!
Python
2
star
63

zulipbot

A ChatGPT Zulip bot
Python
1
star
64

iphoneconverter

A small script to convert a folder of videos into an iPhone format.
1
star
65

reddit-rage-faces

An Opera extension to put ragefaces in every subreddit.
JavaScript
1
star