Skip to main content

memory_oc

pypi version Custom License

Provides methods for creating and managing sessions in body_oc projects.

Please see LICENSE for further information.

See Releases for changes from release to release.

Contents

Module Install

Requires

memory_oc requires python 3.10 or higher

Install via pip

pip install memory_oc

[ top / contents ]

Configuration

Memory requires the use of a config_oc config.json file. See config_oc for more info.

{
  "memory": {
    "redis": "session"
  },

  "redis": {
    "session": {
      "host": "redis.mydomain.com",
      "db": 1
    }
  }
}

The redis section lists Redis connections by name and details to connect. Then memory.redis specifies which connection to use to create the sessions on.

[ top / contents ]

Methods

Memory comes with four methods, to close, create, from_dict and load sessions.

close

Immediately closes and deletes a session from Redis.

import memory

# Closes the session by key
memory.close(somekey)

[ top / contents / methods ]

create

Creates a new session. Takes 3 optional arguments

Argument Type Description
key str The key to use to create the session in Redis.
ttl unsigned integer The time to live in seconds for the session.
data dict The initial data to be stored in the session.
import memory

# Creates a 10 minutes session
session = memory.create(ttl = 600, data = {
	'email': 'sam@somedomain.com',
	'name': 'Sam'
})

# Stores it in Redis
session.save()

# Returns the generated session key
return session.key()

[ top / contents / methods ]

from_dict

Returns a new instance generated from a dict returned by to_dict

import memory

# Load a session
session = memory.load(somekey)

# Convert to a dict
d = session.to_dict()

# Revert to a session
session_copy = memory.from_dict(d)

[ top / contents / methods ]

load

Loads a session from a passed key.

import memory

# Loads the session data from Redis
session = memory.load(somekey)

# Change data
session['name'] = 'Samuel'

# Store it in Redis
session.save()

[ top / contents / methods ]

Class

The class is what is returned from the create, from_dict, and load methods

close

Closes the session in Redis, making it no longer available to anyone.

import memory

# Load the session
session = memory.load(somekey)

# Close the session
session.close()

[ top / contents / class ]

extend

Extends the TTL of the session by the initial TTL given.

import memory

# Load the session
session = memory.load(somekey)

# Extend the session
session.extend()

[ top / contents / class ]

key

Returns the key of the session.

import memory

# Create the session
session = memory.create()

# Print the key
print(session.key())

[ top / contents / class ]

save

Stores changes in Redis after updates.

import memory

# Load a session
session = memory.load(somekey)

# Make changes
session['name'] = 'Samuel'

# Save changes
session.save()

[ top / contents / class ]

to_dict

Returns a dict representation of the instance which can be printed / converted or converted to json. Can be turned back into an instance by passing it to from_dict

import memory

# Load a session
session = memory.load(somekey)

# Print to console
print(session.to_dict())

[ top / contents / class ]

ttl

Getter / Setter for the TTL on the session.

Set

import memory

# Load session
session = memory.load(somekey)

# Returns the current ttl
session.ttl()

# Updates the ttl to 5 minutes and refreshes the session
session.ttl(300)

[ top / contents / class ]

update

Works the same as dict update() so you can store multiple keys at once

import memory

# Load session
session = memory.load(somekey)

# Update multiple fields
session.update({
	'name': 'Samuel',
	'phone': '(555) 123-4567'
})

# Save changes
session.save()

[ top / contents / class ]

Metadata

Release files for memory-oc 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memory-oc 1.0.4
File Size Uploaded Provenance Actions
memory_oc-1.0.4.tar.gz 6.8 kB Without provenance Details for memory_oc-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for memory-oc 1.0.4
File Interpreter ABI Platform Actions
memory_oc-1.0.4-py3-none-any.whl Python 3 none any Details for memory_oc-1.0.4-py3-none-any.whl

Total release size: 13.6 kB

Release files / memory_oc-1.0.4.tar.gz

Download URL memory_oc-1.0.4.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a197d955b15e63d6bea57b9b55dc7e4bf06fd3343b7a02745415a91ab20e5b18
BLAKE2b-256 checksum
How to use checksums
78b48cd8116d8cfd13bbe98c987056e8fbf5ccb67242b6e77022f8fbc0e34ece
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / memory_oc-1.0.4-py3-none-any.whl

Download URL memory_oc-1.0.4-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d64f54c4f21779d7f11d97e916e8a21af5bfa98eca5d8ec07c2e3ec87d563ab3
BLAKE2b-256 checksum
How to use checksums
d6142f91f3ae2611b3279a59b09ec4a01c0f7f772180424462250ae2e43e1a56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for memory-oc 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page