Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.0 #2

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f0ec162
🧑‍💻 use rye instead of poetry
thrzl Apr 21, 2024
d252ca6
🎨 change module structure
thrzl Apr 21, 2024
38bf6e2
🔧 update pyproject.toml and explicitly add pytest
thrzl Apr 21, 2024
38014d4
✅ improve benchmarks
thrzl Apr 21, 2024
dc518ec
📝 update documentation
thrzl Apr 21, 2024
6c15d78
🚧 combine database and tabledatabase
thrzl Apr 21, 2024
b2a37a7
🧑‍💻 get type hints for replit db in benchmark code
thrzl Apr 21, 2024
d83ace2
♻️ inch closer to a similar api to replit-py
thrzl Apr 21, 2024
17c42bf
✅ add/fix tests
thrzl Apr 21, 2024
2628f65
🐛 remove default db
thrzl Apr 21, 2024
f6f3e40
🚚 change submodule name to avoid confusion
thrzl Apr 21, 2024
cbd93d4
🔨 fix benchmark
thrzl Apr 21, 2024
7cfb539
♻️ more parity
thrzl Apr 21, 2024
0d6059d
🎨 update formatting
thrzl Apr 21, 2024
707dc22
🚨 mypy gets mad that there's no stubs
thrzl Apr 21, 2024
2d0be45
✨ get started on async support
thrzl Apr 21, 2024
0074a2b
🐛 fix database argument bug
thrzl Apr 21, 2024
5494f39
🚚 move async to asynchronous to avoid confusion
thrzl Apr 21, 2024
2c7ad0f
✅ add async tests
thrzl Apr 21, 2024
5633fe6
🔥 remove old print statements
thrzl Apr 21, 2024
0e3d398
🥅 improve safety for key deletion
thrzl Apr 21, 2024
3c41eea
🔥 get rid of req function
thrzl Apr 21, 2024
dca7b0e
🎨 format with ruff
thrzl Apr 21, 2024
9178080
✨ add get/setitem methods to database
thrzl Apr 21, 2024
a500948
📝 improve readme docs
thrzl Apr 21, 2024
62fd0d9
✨ add __delitem__ method
thrzl Apr 21, 2024
841fa30
➕ use pytest-asyncio + change version
thrzl Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/__pycache__/*
dist
.mypy_cache
.env*
.env*
.venv
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.2
66 changes: 29 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
![PyPI - Downloads](https://img.shields.io/pypi/dm/repltable?style=for-the-badge)
![code style](https://img.shields.io/badge/code%20style-black-black?style=for-the-badge&logo=python)

this is a project is to make it so that you can have tables in the replit db.

the main annoyance (for me) with replit is that it reverts a lot of database file changes, which forces you to use the repl.it database. also, you can't group together keys, and it takes *FOREVER* to install, due to it installing flask, aiohttp and a ton of other things you don't need for the database.
this is a better wrapper for the replit db built in to the platform. boating much higher performance and more features, repltable is the best way to interact with replit databases.

## ⚙️ installation
```bash
Expand All @@ -14,57 +12,51 @@ pip install repltable

## 🪴 usage
```python
# if you are using this on replit
from repltable import db

# or...
from repltable import Database
db = Database("https://kv.replit.com/v0/...")

>>> from repltable import Database
>>> db = Database("https://kv.replit.com/v0/...")

# repltable databases work like a dictionary
db.get(foo='bar')
>>> [{'foo': 'bar'}]
# or on replit
>>> db = Database()

# repltable auto-creates tables if they don't exist
db.insert(dict(foo='bar'))

# you can get one, or get all matching documents
db.get_one(foo='bar')
>>> {'foo': 'bar'}
# regular key/value pairs
>>> db.get('bar')
"foo"

# set new values
>>> db.set("baz", "qux")
```
you can also group keys together as 'tables'. they're created on the fly if they don't already exist.
```py
>>> table = db.get_table("users")

# you can also group keys together
from repltable import TableDatabase

table = TableDatabase.get("users")
# from here, it behaves as a regular database

table.get(foo='bar')
>>> [{'foo': 'bar'}]
# from here, you can filter rows by their attributes
>>> table.get(role='admin')
[{'username': 'thrzl', 'id': '1234', 'role': 'admin'}, ...]

# repltable auto-creates tables if they don't exist
table.insert(dict(foo='bar'))
# insert full rows at a time
>>> table.insert({'username': 'lzrht', 'id': '4321', 'role': 'member'})

# you can get one, or get all matching documents
table.get_one(foo='bar')
>>> {'foo': 'bar'}
>>> table.get_one(username='lzrht')
{'username': 'lzrht', 'id': '4321', 'role': 'member'}
```
## ❓ why not just use replit-py?
well, my goal is to make it so that you can use repl.it databases without having to use replit-py. replit-py has **27** dependencies. repltable has **2**.
well, my goal is to make it so that you can use repl.it databases without having to use replit-py. replit-py has **27** dependencies. repltable has **1**.

repltable is also **significantly faster** than replit-py, thanks to it caching the keys in memory.

plus, repltable has more features:
- caching (auto-updates itself for accuracy!)
- groups of keys (named tables)
- uses more efficient queries (you can **filter** keys!)
- **local caching**, where the data is stored in memory as well as remotely
- **"table" support**
- **drop-in replacement** for replit-py's database


## 👥 contributing
to contribute, fork the repo, make a branch, and send a pull request.

for local development, you can install the dependencies with poetry:
for local development, you can install the dependencies with **[rye](rye-up.com)**:
```bash
poetry install
rye sync
```

## 📜 license
Expand Down
13 changes: 10 additions & 3 deletions bench_replit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from replit import db
from replit import db, Database # type: ignore
from timeit import timeit

db: Database = db
db.set("test", "item")


def bench_replit():
db.get("amog")
db.get("test")


print(timeit(bench_replit, number=100))

print(timeit(bench_replit, number=10))
del db["test"]
13 changes: 10 additions & 3 deletions bench_repltable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from timeit import timeit
from repltable import db
from repltable import Database # type: ignore

db = Database()
db.set("test", "item")


def bench_repltable():
db.get("amog")
db.get("test")


print(timeit(bench_repltable, number=100))

print(timeit(bench_repltable, number=10))
del db["test"]
51 changes: 29 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
[tool.poetry]
[project]
name = "repltable"
version = "3.0.0"
version = "4.0.0"
description = "a better replit database for python"
authors = ["terabyte. <terabyte@terabyteis.me>"]
authors = [
{ name = "te", email = "thrzl@icloud.com" }
]
dependencies = [
"httpx>=0.27.0",
]
readme = "README.md"
repository = "https://github.com/terabyte3/repltable"
requires-python = ">= 3.8"
keywords = ["replit", "database", "table", "nosql", "db", "datastore", "repl", "repl.it", "replit-py"]
classifiers = [
"Topic :: Database",
]
packages = [
{ include = "repltable" }
]

[tool.poetry.dependencies]
python = "^3.8"
orjson = "^3.6.8"
urllib3 = "^1.26.9"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
black = "^21.7b0"
bandit = "^1.7.0"
mypy = "^0.910"
types-cachetools = "^4.2.2"
pytest-aio = "^1.3.2"
python-dotenv = "^0.20.0"
[tool.rye]
managed = true
dev-dependencies = [
"ruff>=0.4.1",
"bandit>=1.7.8",
"types-cachetools>=5.3.0.7",
"python-dotenv>=1.0.1",
"icecream>=2.1.3",
"replit>=3.6.2",
"pytest>=8.1.1",
"pytest-asyncio>=0.23.6",
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src/repltable"]
6 changes: 0 additions & 6 deletions repltable/__init__.py

This file was deleted.

Binary file removed repltable/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed repltable/__pycache__/database.cpython-38.pyc
Binary file not shown.
51 changes: 0 additions & 51 deletions repltable/db.py

This file was deleted.

Loading