Skip to main content

Python Ragic API client for data loading and manipulation.

Project description

Python Ragic

A Python client for interacting with the Ragic API. This library simplifies making requests to Ragic databases, handling authentication, and working with records.

PyPI Downloads


Table of Contents


Features

  • Easy authentication and connection setup
  • Read data
  • Write new data
  • Modify existing records
  • Delete records
  • Get single records
  • Upload files
  • Download files

Getting Started

  1. Get your API key from Ragic. link

    1.1. Add environment variables to .env file:

    • RAGIC_URL
    • RAGIC_NAMESPACE
    • RAGIC_API_KEY
  2. Setup structure.yaml.

    2.1. Follow the structure file to define the structure of your database.

    2.2. Retrieve the field id from Ragic. link

  3. Install the package using pip:

    pip install python-ragic
    

Code Snippets

Load Data (Table-level)

from ragic import RagicAPIClient

client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)

TAB_NAME = "Sales Management System"
TABLE_NAME = "customer"

data_dict = client.load(
    TAB_NAME,
    TABLE_NAME,
    conditions=[("gender", OperandType.EQUALS, "Male")],
    offset=0,
    size=10,
    other_get_params=OtherGETParameters(subtables=False, listing=False),
    ordering=Ordering(order_by="customer_id", order=OrderingType.ASC),
)

if data_dict:
    with open("data.json", "w", encoding="utf-8") as f:
        f.write(json.dump(data_dict, f, indent=4))
else:
    print("No data found.")

Write new data to Ragic database

from ragic import RagicAPIClient

client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)

TAB_NAME = "Sales Management System"
TABLE_NAME = "customer"

# For field that takes attachment, provide the file path
# If more than one file, provide a list of file paths
data_dict = {
    "Name": "John Doe",
    "Age Group": "41 - 50",
    "Race": "Chinese,
}

resp_dict = client.write_new_data(
    TAB_NAME, TABLE_NAME, data=data_dict
)
if resp_dict:
    with open("write_response.json", "w", encoding="utf-8") as f:
        f.write(json.dump(resp_dict, f, indent=4))
    print("Record created successfully.")
else:
    print("Failed to create record.")

Modify Data (single record)

from ragic import RagicAPIClient

client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)

TAB_NAME = "Sales Management System"
TABLE_NAME = "customer"

# For field that takes attachment, provide the file path
# If more than one file, provide a list of file paths
# When modifying a record with an attachment, 
# it adds a new file instead of replacing the existing one.

# To replace the existing file, set None to the field name, 
# Take note, this approach deletes all existing files from the field.
# Call upload_file method to upload the new file.
data_dict = {
    "Name": "John Doe",
    "Age Group": "41 - 50",
    "Race": "Chinese"
}
record_id = "<ragicId>"  # Replace with the actual record ID

resp_dict = client.modify_data(
    TAB_NAME,
    TABLE_NAME,
    data=data_dict,
    record_id=record_id
)

Delete Data (single record)

from ragic import RagicAPIClient
client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)

TAB_NAME = "Sales Management System"
TABLE_NAME = "customer"

record_id = "<ragicId>"  # Replace with the actual record ID

resp_dict = client.delete_data(
    TAB_NAME,
    TABLE_NAME,
    record_id=record_id
)

Get Data (single record)

from ragic import RagicAPIClient
client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)

TAB_NAME = "Sales Management System"
TABLE_NAME = "customer"

record_id = "<ragicId>"  # Replace with the actual record ID

resp_dict = client.get_data(
    TAB_NAME,
    TABLE_NAME,
    record_id=record_id
)

Upload files

from ragic import RagicAPIClient
client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)
TAB_NAME = "Sales Management System"
TABLE_NAME = "customer"
record_id = "<ragicId>"  # Replace with the actual record ID

field_name = "file_upload_field"  # Replace with the actual field name
file_path = "path/to/your/file.png"  # Replace with the actual file path

resp_dict = client.upload_file(
    TAB_NAME,
    TABLE_NAME,
    record_id=record_id,
    field_name=field_name,
    file_path=file_path
)

Download files

from ragic import RagicAPIClient

client = RagicAPIClient(
    base_url=None,
    namespace=None,
    api_key=None,
    version=3,
    structure_path="structure.yaml",
)

# format xxxxx@filename.file_extension
file_identifier = "<fileIdentifier>"  # Replace with the actual file identifier
output_path = "path/to/save/file.png"  # Replace with the desired output path

resp_dict = client.download_file(
    file_identifier=file_identifier,
    output_path=output_path
)

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

python_ragic-0.3.1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

python_ragic-0.3.1-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file python_ragic-0.3.1.tar.gz.

File metadata

  • Download URL: python_ragic-0.3.1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for python_ragic-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c6a620f5a0ccb853c0226f9a90424dd8c1d7283dd1e91c30a76b9d2a41ebc4db
MD5 5762ceb1d4da3e5235dac6cf9310c761
BLAKE2b-256 e280ffa0bc4453b0fd8b3e657a6f8446b8018f88b775f750430e8ac22bc2cb81

See more details on using hashes here.

File details

Details for the file python_ragic-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: python_ragic-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for python_ragic-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e8fa76cac9810ac17c9ffc9c4ad082c5ec3662b205ecfa5e6393f8265810be4
MD5 e9aa43c8e6a85defa00a75ad55eee76a
BLAKE2b-256 0910f7d73ced63213704c47f6975f333aad2284d0edba790ede4dc7733c77bc4

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