Skip to main content

ORM-like API MongoDB for Python language.

Project description

Logo

ramifice

ORM-like API MongoDB for Python language.

Build Status Docs PyPI pyversions PyPI status PyPI version fury.io PyPI Downloads GitHub license GitHub repository

Ramifice is built around PyMongo.
For simulate relationship Many-to-One and Many-to-Many,
a simplified alternative (Types of selective fields with dynamic addition of elements) is used.
The project is more concentrated for web development or for applications with a graphic interface.

Supports MongoDB 3.6, 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.
For more information see PyMongo.

Project Status

Documentation

Online browsable documentation is available at https://kebasyaty.github.io/ramifice/.

Requirements

View the list of requirements.

Installation

  1. Install MongoDB (if not installed):
    Fedora Ubuntu

  2. Run:

# Ubuntu:
sudo apt install gettext
gettext --version
# Fedora:
sudo dnf install gettext
gettext --version
# Windows:
https://mlocati.github.io/articles/gettext-iconv-windows.html
gettext --version

cd project_name
poetry add ramifice
  1. Add the configuration and public directories to the root of your project:
    https://github.com/kebasyaty/ramifice/tree/main/config
    https://github.com/kebasyaty/ramifice/tree/main/public

Usage

It is recommended to look at examples here.

from datetime import datetime
from pymongo import AsyncMongoClient
from ramifice import model, translations
from ramifice.fields import TextField, EmailField, DateField
from ramifice.migration import Monitor
import pprint

@model(service_name="Accounts")
class User:
    def fields(self, gettext):
        # ngettext = translations.get_translator(
        #     translations.CURRENT_LOCALE).ngettext
        self.username = TextField(
            label=gettext("Username"),
            required=True,
            unique=True,
        )
        self.first_name = TextField(
            label=gettext("First name"),
            required=True
        )
        self.last_name = TextField(
            label=gettext("Last name"),
            required=True,
        )
        self.email = EmailField(
            label=gettext("Email"),
            required=True,
            unique=True,
        )
        self.birthday = DateField(label=gettext("Birthday"))
        self.password = DateField(label=gettext("Password"))
        self.сonfirm_password = DateField(
            label=gettext("Confirm password"),
            # If true, the value of this field is not saved in the database.
            ignored=True,
        )

    async def add_validation(self) -> dict[str, str]:
        """It is supposed to be use to additional validation of fields.
        Format: <"field_name", "Error message">
        """
        error_map: dict[str, str] = {}
        if self.password != self.сonfirm_password:
            error_map["password"] = "Passwords do not match!"
        return error_map

client = AsyncMongoClient()
await Monitor(
    database_name="test_db",
    mongo_client=client,
).migrat()

user = User()
user.username.value = "pythondev"
user.first_name.value = "John"
user.last_name.value = "Smith"
user.email.value = "John_Smith@gmail.com"
user.birthday.value = datetime(2000, 1, 25)
user.password.value = "12345678"
user.сonfirm_password.value = "12345678"

if not await user.save():
    # Convenient to use during development.
    user.print_err()

doc_count = await User.estimated_document_count()
print(f"Document count: {doc_count}") # => 1

user_details = await User.find_one_to_raw_doc({"_id": user._id.value})
pprint.pprint(user_details)

await user.delete()

doc_count = await User.estimated_document_count()
print(f"Document count: {doc_count}") # => 0

await client.close()

See more examples here.

Model Parameters

See the documentation here.

( only service_name is a required parameter )
Parameter Default Description
service_name no Examples: Accounts | Smartphones | Washing machines | etc ...
fixture_name no The name of the fixture in the config/fixtures directory (without extension).
Examples: SiteSettings | AppSettings | etc ...
db_query_docs_limit 1000 limiting query results.
is_migrat_model True Set to False if you do not need to migrate the Model to the database.
This can be use to validate a web forms - Search form, Contact form, etc.
is_create_doc True Can a Model create new documents in a collection?
Set to False if you only need one document in the collection and the Model is using a fixture.
is_update_doc True Can a Model update documents in a collection?
is_delete_doc True Can a Model remove documents from a collection?

Example:

@model(
    service_name="ServiceName",
    fixture_name="FixtureName",
    db_query_docs_limit=1000,
    is_migrat_model=True,
    is_create_doc = True,
    is_update_doc = True,
    is_delete_doc = True,
)
class User:
    def fields(self, gettext):
        self.username = TextField(
            label=gettext("Username"),
            required=True,
            unique=True,
        )

Contributing

  1. Fork it (https://github.com/kebasyaty/ramifice/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Install for development of Ramifice

# Ubuntu:
sudo apt install gettext
gettext --version
# Fedora:
sudo dnf install gettext
gettext --version
# Windows:
https://mlocati.github.io/articles/gettext-iconv-windows.html
gettext --version

cd project_name
poetry install --with dev docs

Contributors

  • kebasyaty Gennady Kostyunin - creator and maintainer

Changelog

View the change history.

License

This project is licensed under the MIT.

Project details


Release history Release notifications | RSS feed

This version

0.2.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ramifice-0.2.3.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ramifice-0.2.3-py3-none-any.whl (75.6 kB view details)

Uploaded Python 3

File details

Details for the file ramifice-0.2.3.tar.gz.

File metadata

  • Download URL: ramifice-0.2.3.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.3 Windows/10

File hashes

Hashes for ramifice-0.2.3.tar.gz
Algorithm Hash digest
SHA256 be16d4d0a5b7524e77902362e35729691181016595973ba555b42a8f044d60c7
MD5 0837d412e6810fe195e6647ec7f8949c
BLAKE2b-256 6de4cda76e55aa41746b40f884b3ccc9944c2d9de8b718bd3137239dc16e4e70

See more details on using hashes here.

File details

Details for the file ramifice-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: ramifice-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 75.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.3 Windows/10

File hashes

Hashes for ramifice-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 01af7f5624cce4d2e132b92b73e549eab44b0702f7f5dd647761eff18701f708
MD5 a5d8206ceecbd9f8f0e626e898f6ebaa
BLAKE2b-256 e3dd0ac445ced0c226aa2a9251b25ace6a6ce59c1d57c90ea9ae2238c5f4817e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page