Databases should be Effortless.
Project description
Databases should be Effortless.
Effortless has one objective: be the easiest database. It's perfect for beginners, but effortless for anyone.
Quickstart
You can install Effortless easily, if you have pip and Python 3.9 or higher installed.
pip install effortless
Usage
We offer 3 tiers of effort when using our databases. If this is your first time using a database, try out the Effortless usage below. If you are working on a simple project, you should take a look at the Basic usage docs. Overachievers may want to try our Advanced features.
Effortless Usage
from effortless import db, Field
# Add items to the database
db.add({"name": "Alice", "age": 30})
db.add({"name": "Bob", "age": 25})
# Get all items from the DB
all_items = db.get_all()
print(all_items)
# Output: {'1': {'name': 'Alice', 'age': 30}, '2': {'name': 'Bob', 'age': 25}}
# Get items based on a field
# This will get all items where their name is Alice
result = db.filter(Field("name").equals("Alice"))
print(result) # Output: {'1': {'name': 'Alice', 'age': 30}}
# Wipe the database
db.wipe()
print(db.get_all()) # Output: {}
Basic Usage
from effortless import EffortlessDB, Field
# Create a new Effortless instance
db = EffortlessDB()
# Add items to the database
db.add({"name": "Charlie", "age": 35})
db.add({"name": "David", "age": 28})
# Filter items
result = db.filter(Field("age").greater_than(30))
print(result) # Output: {'1': {'name': 'Charlie', 'age': 35}}
Advanced Usage
from effortless import EffortlessDB, EffortlessConfig, Field, Query
# Create a new Effortless instance with a custom directory
db = EffortlessDB("advanced_db")
db.set_directory("/path/to/custom/directory")
# Add multiple items
db.add({"id": 1, "name": "Eve", "skills": ["Python", "JavaScript"], "joined": "2023-01-15"})
db.add({"id": 2, "name": "Frank", "skills": ["Java", "C++"], "joined": "2023-02-20"})
db.add({"id": 3, "name": "Grace", "skills": ["Python", "Ruby"], "joined": "2023-03-10"})
# Complex filtering
python_devs = db.filter(
Field("skills").contains("Python") &
Field("joined").between_dates("2023-01-01", "2023-02-28")
)
print(python_devs)
# Custom query using Query class
custom_query = Query(lambda item: len(item["skills"]) > 1 and "Python" in item["skills"])
multi_skill_python_devs = db.filter(custom_query)
print(multi_skill_python_devs)
# Update configuration
db.configure(EffortlessConfig({"readonly": True}))
# The database contents are now read-only
db.add({"Anything": "will not work"}) # Raises an error
New Filtering Capabilities
Effortless 1.1 introduces powerful filtering capabilities using the Field
class:
equals
: Exact matchcontains
: Check if a value is in a string or liststartswith
,endswith
: String prefix and suffix matchinggreater_than
,less_than
: Numeric comparisonsmatches_regex
: Regular expression matchingbetween_dates
: Date range filteringfuzzy_match
: Approximate string matchingpasses
: Apply a custom function to filter itemsis_type
: Check the type of a field
You can combine these filters using &
(AND) and |
(OR) operators for complex queries.
result = db.filter(
(Field("age").greater_than(25) & Field("skills").contains("Python")) |
Field("name").startswith("A")
)
For even more flexibility, you can use the passes
method with a custom function:
def is_experienced(skills):
return len(skills) > 3
result = db.filter(Field("skills").passes(is_experienced))
You can also check the type of a field:
result = db.filter(Field("age").is_type(int))
These new filtering capabilities make Effortless more powerful while maintaining its simplicity and ease of use.
Why Effortless?
If you're actually reading this section, it seems like you don't care about the whole "effortless" part. If you did, you'd already have your own million-dollar startup with one of our databases by now. So, here's some other reasons Effortless stands out:
🛡️ Safety First
All your data is safe, lossless, and locally stored by default. You can begin persistent, automatic backups, keyed database encryption, and more with a couple lines of Python.
new_configuration = EffortlessConfig()
new_configuration.backup = "/path/to/backup"
db.configure(new_configuration)
All your data is now automatically backed up to the specified path until you edit the configuration again.
🔍 Powerful Querying
Effortless introduces a unique and intuitive object-oriented filter system. You can create a reusable Field condition with logical operators to find anything from your database.
is_bboonstra = Field("username").equals("bboonstra")
is_experienced = Query(lambda item: len(item["known_programming_languages"]) > 5)
GOATs = db.filter(is_bboonstra | is_experienced)
You've just filtered a thousand users into a couple with complex conditioning, and it was effortless.
🎓 Perfect for Learning
Whether you're a beginner or an experienced developer, Effortless provides a gentle learning curve without sacrificing power, making it an ideal choice for educational environments and rapid prototyping.
This project isn't a database; it's a philosophy: data management should be simple, powerful, and... Effortless.
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
Hashes for Effortless-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed0969760ee20be3978054ab3014669e930ec374aee20bdd390d9cfd2100882 |
|
MD5 | 23104f01239df15b77727f849c6051f4 |
|
BLAKE2b-256 | ab70d8e69c13781967f5268d7fd7e1a42ff4109fcd833960d2a71bdff961f658 |